0

我有图像列表,鼠标悬停在其下方显示选项框,其中嵌入了要从中复制的代码输入框。现在我在其上实现了 zeroclipboard,用于使复制功能在单击时起作用,因此当我将鼠标悬停在图像上时,它会正确显示选项框,但是当我用鼠标单击输入框以复制代码时,选项会得到关闭,认为它不再在选项 div 中,因为 zeroclipboard 在它上面有 div,所以鼠标继续它并且它被关闭。

所以解决方案是在选项 div 中创建该 div,它一直在处理,但现在 zeroclipboard div 样式显示错误,我不知道如何修复它。

以下是 zeroclipboar 的样式,我不知道在上面设置什么样式,所以它在输入框上方,所以我可以点击它,所以它像往常一样工作正常。

    on line 107 in zeroclipboard.js
var style = this.div.style;
    style.position = 'absolute';
    style.left = '' + box.left + 'px';
    style.top = '' + box.top + 'px';
    style.width = '' + box.width + 'px';
    style.height = '' + box.height + 'px';
    style.zIndex = zIndex;
4

4 回答 4

2
$("input[name='htmlcode'], input[name='directlink'], input[name='emaillink'], input[name='imgcode']").live('mouseover', function() {

        clip = new ZeroClipboard.Client();
        clip.setHandCursor( true );
        clip.setText($(this).val());

        var width = $(this).width();
        var height =  $(this).height()+10;
        var flash_movie = '<div>'+clip.getHTML(width, height)+'</div>';
        // make your own div with your own css property and not use clip.glue()
        flash_movie = $(flash_movie).css({
            position: 'relative',
            marginBottom: -height,
            width: width,
            height: height,
            zIndex: 101
            })
        .click(function() { // this puts copied indicator for showing its been copied!
            $(this).next('input').indicator({className: 'copied', wrapTag: 'div', text: 'Copied!', fadeOut: 'slow', display: 'after'});
        });

        $(this).before(flash_movie); // if you want to put after and not before, then you have to change the marginBottom to marginTop
    });
于 2009-10-22T05:08:07.590 回答
0

我不知道您的代码是什么样的,但是当您使用悬停或鼠标悬停/鼠标悬停显示选项框时,只需包含零剪贴板 div ......类似这样的东西(我相信这是要使用的正确对象 ID):

$('img.someimage, .optiondiv, #ZeroClipboardMovie_1').hover(function(){
  $('.optiondiv')
  // positioning stuff here
  .show()
})
于 2009-10-22T04:42:24.273 回答
0

当我使用零剪贴板时,我注意到最好在不需要时将其移动到负左位置。如:

#clipboardContainer {position:absolute; top:0; left:-1000px;}

我不太了解您的问题,但是动态地将其从引起问题的位置移开可能是解决问题的一种方法。

于 2009-10-24T21:18:38.013 回答
0

只为您的兴趣:

我的方法使用数据属性来激活复制功能。除此之外,它在根元素上设置悬停和活动类。

用法:

HTML:

 <button data-zc-copy-value="this is the text to copy">some text<button>

Javascript:

  $(document).on('mouseover', '*[data-zc-copy-value]', function() {
      var that = $(this),
          width = that.outerWidth(),
          height =  that.outerHeight();

      if(that.data("zc-activated") !== "true"){
        // init new ZeroClipboard client
        clip = new ZeroClipboard.Client();
        clip.setHandCursor( true );
        clip.setText(that.data('zc-copy-value'));

        var flash_movie = '<div>'+clip.getHTML(width, height)+'</div>';
        // make your own div with your own css property and not use clip.glue()
        flash_movie = $(flash_movie).css({
          position: 'relative',
          marginBottom: -height,
          width: width,
          height: height,
          zIndex: 101
        });

        // delegate mouse events
        flash_movie.hover(function(){
          that.addClass('hover');
        },function(){
          that.removeClass('hover');
        });
        flash_movie.mousedown(function(){
          that.addClass('active');
        });
        flash_movie.mouseup(function(){
          that.removeClass('active');
        });

        // add flash overlay
        $(this).before(flash_movie); // if you want to put after and not before, then you have to change the marginBottom to marginTop

        that.data("zc-activated", "true");
      }
    });
于 2012-11-08T11:31:19.280 回答