如何检查元素当前是否正在拖动

时间:2012-05-25 05:58:15

标签: jquery jquery-ui

我希望能够在调用函数时检查事件是否发生。当我使用.draggable()向上和向下拖动我的自定义滚动条时,我调用了一个函数,并且当我的容器滚动时我也调用了一个函数。问题是两者都在同一时间运行,这使得它表现出错误。

所以我的问题是如何执行“if”语句检查滚动条当前是否被拖动,以便我可以阻止它执行函数代码的其余部分?

我不是在询问某个元素是否有“绑定”的事件,而是在某个特定时刻触发该事件。

我可以这样做吗?或者我需要采取另一种方法吗?

以下是我的代码:

$('.container').scroll(function(){
    //get the heights of the container and it's contents and the difference
    //get the height of the scroll bar and it's container and the difference
    //declare the top property of scroll bar from this info
});
function scrolly() {
    //get the heights of the elements described above
    //declare the scrollTop of the container
}
$('.bar').draggable({
    axis: 'y',
    containment: 'parent',    
    drag: function() {
        scrolly();
    }
});

1 个答案:

答案 0 :(得分:13)

<强>更新

您可以使用此条件查明您的栏是否被拖动:

if ($('.bar').is('.ui-draggable-dragging')) {
    return; // bar is being dragged
}
相关问题