ZeroClipboard 添加工具提示时出现问题
我正在尝试使用 Zeroclipboard http://code.google.com/p/zeroclipboard/ 将内容复制到剪贴板并在鼠标悬停在闪光灯上时添加工具提示。但它似乎不起作用。
我的 html 代码:
<div rel="<?php echo $url;?>" class="cp-code">copied code</div>
<div class="test" style="display: none; border: 1px solid #ccc; padding: 8px;">click copy,test,test</div>
我的 js 代码: 我添加了 jquery 库。
ZeroClipboard.setMoviePath("http://example.com/js/ZeroClipboard.swf");
var clip = null;
var url = '';
function init() {
clip = new ZeroClipboard.Client();
clip.setHandCursor( true );
$('.cp-code').mouseover( function() {
clip.setText(this.innerHTML);
$('test').style.display = 'block';
if (clip.div) {
clip.receiveEvent('mouseout', null);
clip.reposition(this);
} else {
clip.glue(this);
}
clip.receiveEvent('mouseover', null);
url = $(this).attr('rel');
});
clip.addEventListener('mouseUp', function(client) {
window.open(url);
});
clip.addEventListener('mouseOut', function (client) {
$('test').style.display = 'none';
});
}
$(document).ready(function() {
init();
});
I'm trying to use Zeroclipboard http://code.google.com/p/zeroclipboard/ to copy stuff to the clipboard and add a tooltip when the mouse hover on the flash. but it doesn't seem to be working.
my html code:
<div rel="<?php echo $url;?>" class="cp-code">copied code</div>
<div class="test" style="display: none; border: 1px solid #ccc; padding: 8px;">click copy,test,test</div>
My js code: i have added the jquery library.
ZeroClipboard.setMoviePath("http://example.com/js/ZeroClipboard.swf");
var clip = null;
var url = '';
function init() {
clip = new ZeroClipboard.Client();
clip.setHandCursor( true );
$('.cp-code').mouseover( function() {
clip.setText(this.innerHTML);
$('test').style.display = 'block';
if (clip.div) {
clip.receiveEvent('mouseout', null);
clip.reposition(this);
} else {
clip.glue(this);
}
clip.receiveEvent('mouseover', null);
url = $(this).attr('rel');
});
clip.addEventListener('mouseUp', function(client) {
window.open(url);
});
clip.addEventListener('mouseOut', function (client) {
$('test').style.display = 'none';
});
}
$(document).ready(function() {
init();
});
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
为什么你希望它在鼠标悬停时发生?我不确定 ZeroClipboard 是否支持这一点。
当我第一次使用 ZeroClipboard 时,我花了一些时间才弄清楚这一点,因为它的实现与正常的有点不同。但是,您不能只调用clip.setText。您必须将剪辑实现“粘合”到控件上。而且你也不能使用 jQuery 对象,你必须将它粘合到实际的 DOM 对象上。
因此,例如:
现在,当您单击该元素时,文本将被复制。我看到您在示例中做了其他一些事情,但无论如何,我认为您缺少的元素是将 DOM 对象粘合到 Clip 的实例,而不是在 jQuery mouseover 事件上调用 Clip.setText。
Why do you want it to happen on mouseover? I'm not sure if ZeroClipboard supports that.
It took me a little while to figure this out when I first used ZeroClipboard because it's implementation is a bit different from normal. However, you can't just call clip.setText. You have to 'glue' the clip implementation to the control. And you can't use the jQuery object either, you have to glue it to the actual DOM object.
So, for example:
So now when you click the element, the text will be copied.I see where your doing some other stuff in your example, but regardless, I think the element your missing is gluing the DOM object to the instance of clip, rather than calling clip.setText on your jQuery mouseover event.