gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-12-03 22:31:14 24 4
gpt4 key购买 nike

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

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

我不是在问一个元素是否“绑定(bind)”了一个事件,而是在问该事件是否在特定时刻被触发。

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

这是我的代码:

$('.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();
}
});

最佳答案

更新

您可以使用此条件来确定您的栏是否被拖动:

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

关于jquery - 如何检查元素当前是否正在拖动,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10749189/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com