问题
I am currently using the zclip/jquery code to allow copying to the clipboard. It is currently attached to a span button. It seems to use a swf file over the button to provide the flash based copy to clipboard feature. The problem that I have is that when I dynamically add new elements to the page, the button position moves down but the SWF position stays the same. Is there anything I can do to have the zclip "follow" the button? Zclip snippet below:
$("#copyToClip").zclip({
path:'include/javascript/ZeroClipboard.swf',
copy:function(){return $("#outputtext").text();}
});
回答1:
The zclip('show') thing actually calls the jquery show method, not the Zclip function.
An other tip would be to trigger the window resize or load event. You can see in the code the reposition function is bound to it.
a(window).bind("load resize", function(){
d.reposition()
})
then everytime, I add/remove element to my page, I call
$(window).trigger('reload');
That does the trick for me.
回答2:
I beleive you can call the 'show' method to refresh the position:
$('#copyToClip').zclip('show');
The site does say "it may not be 100% reliable in every instance." and although it doesn't sound like it'll be an issue in your case it might be worth noting that it won't resize itself if the button has changed size.
来源:https://stackoverflow.com/questions/8842977/zclip-swf-does-not-align-with-button-position-if-button-position-changes