我有一个带有侧滚动条的 jQuery 可拖动容器 div,当我上下滚动时,它不应该是可拖动的。 .infotext 是包含文本的内部 div,包含在设置为 overflow:auto 的#infobody 中。我需要一种方法来在选择滚动条时取消 div 上的可拖动功能。这是我的代码:
$(".lsidebar").draggable({"scroll":false});
.lsidebar #infobody{
cursor:default;
position:absolute;
width:100%;
overflow:auto;
margin:23px 0 0 0;
z-index:14;
}
#infobody .infotext{
cursor:default;
position:relative;
width:100%;
z-index:14;
color:#969696;
}
最佳答案
实际上你可以在draggable中使用“cancel”属性来防止滚动事件影响到draggable元素。
例如:
如果你的html是这样的...
<div class="draggable">
<div class="scrollable"></div>
</div>
对于 js:
$('.draggable').draggable({
cancel: '.scrollable'
});
当您在该特定区域滚动时,外部可拖动元素将被暂时禁用。
关于jquery - 如何在 jQuery 中聚焦滚动条时禁用可拖动的 div,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3300765/