jQuery 中滚动条聚焦时如何禁用可拖动 div
我有一个带有侧滚动条的 jQuery 可拖动容器 div,当我上下滚动时,该滚动条不应该是可拖动的。 .infotext 是包含文本的内部 div,包含在 #infobody 中,设置为 Overflow:auto。我需要一种方法来在选择滚动条时取消 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;
}
I have a jQuery draggable container div with a side scroll bar that should not be draggable when I am scrolling up and down. .infotext is the inner div that has the text, contained within #infobody which is set to overflow:auto. I need a way to negate the draggable function on the div when the scrollbar is selected. Here is my code:
$(".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;
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(6)
实际上你可以在draggable中使用“cancel”属性来防止滚动事件影响到draggable元素。
例如:
如果你的 html 是这样的...
对于 js:
当你在该特定区域滚动时,外部可拖动元素将被暂时禁用。
Actually you can use "cancel" property in draggable to prevent the scrolling event affect to the draggable element.
For example:
if your html is like this...
for the js:
When you scrolling in that specific area, the outer draggable element will be temporary disabled.
这对我有用,我使用 jquery ui 1.8.2。
this works for me, im using jquery ui 1.8.2.
此问题的解决方法(因为由于某种原因,最近没有人回答我的问题)是用名为 jScrollPane 的 jQuery 滚动条替换默认浏览器滚动条。这样做允许我使用插入的滚动条 ID 作为选择器来禁用可拖动...如下所示:
A workaround to this problem (because for some reason no one is answering my questions as of recently) was to substitute the default browser scrollbar with a jQuery scrollbar known as jScrollPane. Doing this allows me to use the inserted scrollbar ID as a selector to disable draggable...like so:
我想这可能会很好用
I guess this might work fine
尝试在 page_wrapper 的 css 中添加
overflow:hidden;
。Try to add
overflow:hidden;
in the css of the page_wrapper.您可以绑定到当前元素及其所有子元素和父元素上的滚动事件,如下所示,滚动时将禁用拖动:
检查此 JSFIDDLE。
You can bind to the scroll event on the current element and all its children and parents as done below, the dragging will be disabled while scrolling on:
check this JSFIDDLE.