jQuery Live和可拖动 [英] Jquery Live and Draggable

查看:79
本文介绍了jQuery Live和可拖动的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用Jquery Live绑定将click事件绑定到图像.第一次单击图像时,将启动simplemodal弹出窗口,并且可拖动的效果很好.此后,仍然会启动simplemodal弹出窗口,并且可拖动项将不会拖动.有什么想法吗?

I am binding a click event to an image using Jquery Live binding.  The first time I click on the image the simplemodal popup launches and draggable works fine.  After that, the simplemodal popup still launches and the draggable item will not drag.  Any ideas?

实时点击事件的代码:

$("table tr td img:not(.Help)").live("click", function(){

    $("#draggable").draggable({
        containment: 'parent',
        drag: function(e, ui){
            alert("dragging");
        }
    });

    $("#modal").modal({
        onShow: function(){
            $("html").css("overflow", "hidden");
        },
        onClose: function(){
            $("html").css("overflow", "auto");
            $("table tr td img").live("click", function(){});
            $.modal.close();
        }
    });
});

推荐答案

万一将来有人要寻找解决方案,解决方案是将可拖动"代码放入onShow回调中.

In case anyone looks for this in the future the solution was to put the "draggable" code in the onShow callback.

$("table tr td img:not(.Help)").live("click", function(){ 

    $("#modal").modal({ 
        onShow: function(){
             $("#draggable").draggable({ 
                containment: 'parent', 
                drag: function(e, ui){ 
                    alert("dragging"); 
                } 
            });  
            $("html").css("overflow", "hidden"); 
        }, 
        onClose: function(){ 
            $("html").css("overflow", "auto"); 
            $("table tr td img").live("click", function(){}); 
            $.modal.close(); 
        } 
    }); 
}); 

这篇关于jQuery Live和可拖动的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆