我有图像列表,鼠标在它下面有选项框显示,它包含了要复制的代码输入框。现在我在它上面实现了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;
有帮助吗?

解决方案

$("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
    });

其他提示

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

$('img.someimage, .optiondiv, #ZeroClipboardMovie_1').hover(function(){
  $('.optiondiv')
  // positioning stuff here
  .show()
})

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

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

我不太明白你的问题,但是动态地将它从导致问题的地方移开可能是解决问题的一种方法。

仅为了您的兴趣:

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

用法:

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");
      }
    });
许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top