使用jquery.event.drag延迟dragstart

delaying dragstart with jquery.event.drag

本文关键字:延迟 dragstart drag event jquery 使用      更新时间:2023-09-26

我正在使用jquery.event.drag进行元素拖动。我想知道如何延迟拖动。

我试过了:

$('#drag').bind('dragstart', function() {
    setTimeout(function() {
        $('#drag').bind('drag', function(event) {
            $(this).css({
                top: event.offsetY,
                left: event.offsetX
            });
        });
    }, 1000);
});

但它不起作用,正如你在这里看到的:http://jsfiddle.net/hqDyw/是否可以延迟元素的拖动?提前感谢你对我如何让它发挥作用的任何建议。

既然你在使用jQuery,你有没有检查过jQueryUI的可拖动插件?

http://jqueryui.com/demos/draggable/#delay-启动

很容易实现您想要的功能:http://jsfiddle.net/hqDyw/1/