我希望能够在调用函数时检查事件是否发生.当我使用.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();
}
});
Run Code Online (Sandbox Code Playgroud)
Ja͢*_*͢ck 14
更新
您可以使用此条件来确定您的栏是否被拖动:
if ($('.bar').is('.ui-draggable-dragging')) {
return; // bar is being dragged
}
Run Code Online (Sandbox Code Playgroud)