Zeroclipboard 未将 Flash 按钮精确定位在 div 顶部

发布于 2024-11-02 14:39:24 字数 1720 浏览 5 评论 0原文

有趣的是,这在一段时间内完美地发挥了作用,然后突然停止了,据我所知没有任何变化。可能是浏览器缓存的东西。无论如何,我的zeroclipboard代码:

var $j = jQuery.noConflict();
ZeroClipboard.setMoviePath( 'ZeroClipboard.swf' );

$j('document').ready(function() 
{   
    var address = $j('#address').html();
    var clip = new ZeroClipboard.Client();  
    clip.setText( address );
    $j('#get_address_button').mouseover(function() {    
        clip.glue(this);
        clip.addEventListener( 'oncomplete', my_complete );     
    }); 

    function my_complete( client ) {
        alert('The Bitcoin Address: '+address+' has been copied to your clipboard' );   
    }

});

和我的html:

<div id="address" style="display: none"><?php _e($address) ?></div>
<div style="border:1px solid grey; text-align:center; padding:5px; overflow: auto;">    
    <b><?php echo $message ?></b>
    <img src="<?php _e(WP_PLUGIN_URL) ?>/bitcoin-donations-plugin/images/bitcoin_logo<?php _e($image) ?>.png" alt="image here"/>        
    <div style="position:relative; width:100%;">
        <div style="float:left; width:92px; height:40px; background-image:url(<?php _e(WP_PLUGIN_URL) ?>/bitcoin-donations-plugin/images/button.png);""><a href="http://www.weusecoins.com/">What is<br>Bitcoin?</a></div>
        <div style="float:right; width:92px; height:40px; background-image:url(<?php _e(WP_PLUGIN_URL) ?>/bitcoin-donations-plugin/images/button.png);" id="get_address_button">Get My<br>Bitcoin Address</div>
    </div>
</div>

一切正常,但zeroclipboard在胶水顶部创建的隐形闪光按钮(这个); div 放置在其应有位置以北约 25px 处。 有什么想法吗?

funny, this worked for a while perfectly and has suddenly stopped, with AFAIK no changes. probably a browser caching thing. Anyway my zeroclipboard code:

var $j = jQuery.noConflict();
ZeroClipboard.setMoviePath( 'ZeroClipboard.swf' );

$j('document').ready(function() 
{   
    var address = $j('#address').html();
    var clip = new ZeroClipboard.Client();  
    clip.setText( address );
    $j('#get_address_button').mouseover(function() {    
        clip.glue(this);
        clip.addEventListener( 'oncomplete', my_complete );     
    }); 

    function my_complete( client ) {
        alert('The Bitcoin Address: '+address+' has been copied to your clipboard' );   
    }

});

And my html:

<div id="address" style="display: none"><?php _e($address) ?></div>
<div style="border:1px solid grey; text-align:center; padding:5px; overflow: auto;">    
    <b><?php echo $message ?></b>
    <img src="<?php _e(WP_PLUGIN_URL) ?>/bitcoin-donations-plugin/images/bitcoin_logo<?php _e($image) ?>.png" alt="image here"/>        
    <div style="position:relative; width:100%;">
        <div style="float:left; width:92px; height:40px; background-image:url(<?php _e(WP_PLUGIN_URL) ?>/bitcoin-donations-plugin/images/button.png);""><a href="http://www.weusecoins.com/">What is<br>Bitcoin?</a></div>
        <div style="float:right; width:92px; height:40px; background-image:url(<?php _e(WP_PLUGIN_URL) ?>/bitcoin-donations-plugin/images/button.png);" id="get_address_button">Get My<br>Bitcoin Address</div>
    </div>
</div>

Everything works fine but the invisible flash button that zeroclipboard creates on top of the glue(this); div is placed about 25px north of where it should be.
Any ideas?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(5

蘸点软妹酱 2024-11-09 14:39:24

同样在这里,swf 被某个地方的填充物压低,所以过了一会儿我就破解了它。在 ZeroClipboard.js 中更改坐标,如下所示:

 getDOMObjectPosition: function(obj, stopObj) {
        // get absolute coordinates for dom element
        var info = {
            left: 0, 
            top: 0, 
            width: obj.width ? obj.width : obj.offsetWidth, 
            height: obj.height ? obj.height : obj.offsetHeight
        };

Same here, the swf was being pushed down by padding somewhere so after a while I just hacked it. In ZeroClipboard.js change the coordinates as follows:

 getDOMObjectPosition: function(obj, stopObj) {
        // get absolute coordinates for dom element
        var info = {
            left: 0, 
            top: 0, 
            width: obj.width ? obj.width : obj.offsetWidth, 
            height: obj.height ? obj.height : obj.offsetHeight
        };
︶葆Ⅱㄣ 2024-11-09 14:39:24

解决办法:

阅读文档或者其他脚本后把代码贴上去!

在您的页面中,可以包含在页面加载期间减小其大小的元素,例如手风琴或可扩展菜单。

swf 嵌入的值为 top,但页面加载结束时,其他元素都改变了位置。在发生所有事件之后,您的闪光灯应该考虑它

代码:

$(document).ready(function() {
       var clip = new ZeroClipboard.Client();
       clip.setText( 'Copy me!' );
       clip.setHandCursor( true );
       clip.glue( 'd_clip_button' );
});

The solution:

Put the code after reading the document or other scripts!

In your page, can have elements that decreases his size during the loading of the page, such as accordion or expandable menu, for example.

The swf is embedded with a value for the top, but the end of loading of the page, other elements are changed position. Your flash should consider it after all events

The code:

$(document).ready(function() {
       var clip = new ZeroClipboard.Client();
       clip.setText( 'Copy me!' );
       clip.setHandCursor( true );
       clip.glue( 'd_clip_button' );
});
橘虞初梦 2024-11-09 14:39:24

我有类似的问题。我实际上最终做的(振作起来)是用 javascript 移动 .swf。它很脏,我并不自豪,但这个问题已经把我带到了理智的边缘。

如果有人有非黑客解决方案,我会洗耳恭听。

I had a similar problem. What I actually ended up doing (brace yourself), was to move the .swf with javascript. It's as dirty as it gets, and I'm not proud, but this problem has brought me to the edge of sanity here.

If anyone has a non-hacking solution, I'm all ears.

神妖 2024-11-09 14:39:24

值得一提的是,因为它没有在任何其他答案中明确指出:检查以确保您没有任何可能影响定位的 CSS 规则(例如,使用 div 元素选择器)(例如,通过填充或margin) 为 swf 对象所在的 div。

Worth mentioning since it wasn't explicitly called out in any of the other answers: check to make sure you don't have any CSS rules (eg, using a div element selector) that might be affecting the positioning (eg, via padding or margin) of the div that the swf object is in.

深海里的那抹蓝 2024-11-09 14:39:24

有点黑客,但对我有用。基本上使用计时器和延迟来确保页面上的所有内容都已“稳定”,然后手动将 Flash 元素移动到与按钮相同的绝对位置。需要 JQuery。

在 ZeroClipboard.js 文件中,找到创建 flash div 的行:

this.div = document.createElement('div');

并添加以下行:

this.div.id = 'zeroclip_flash';

现在可以通过 id 操作包含 flash 元素的 div。

在所有其他 ZeroClipboard 启动内容之后,添加以下行:

setTimeout(function() {
    $('#zeroclip_flash').offset( $('#copy').offset() );
}, 500);

其中“clip”是粘合目标元素的 ID。

就像我说的,这是一个 hack,但对于我使用 Chrome 来说,似乎没有其他方法可以工作。

Kind of a hack, but works for me. Basically using a timer and delay to make sure everything on the page has "settled", then manually moving the flash element to the same absolute position as the button. Requires JQuery.

In the ZeroClipboard.js file, find the line where the flash div is created:

this.div = document.createElement('div');

And add this line:

this.div.id = 'zeroclip_flash';

Now the div containing the flash element can be manipulated by id.

After all the other ZeroClipboard initiation stuff, add this line:

setTimeout(function() {
    $('#zeroclip_flash').offset( $('#copy').offset() );
}, 500);

Where 'clip' is the ID of the glue target element.

Like I said, it's a hack, but nothing else seems to work for me using Chrome.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文