使用jQuery UI Draggable,如何在使用滚动条时避免拖动?
很久以前,我在应用程序中创建了一个对话框。该对话框非常简单,位置绝对,通过 JavaScript 位于屏幕中央。
现在我已将 jQuery UI 添加到应用程序中,但我不想仅因为它们的工作方式不同而使用 jQuery UI 的对话框。但我确实使用 jQuery UI 使我的对话框可拖动,因为这非常简单:
$('#dialog').draggable();
有一个问题,我的一些对话框有滚动条。
但是使用draggable方法,如果有滚动条,就会出现bug,因为它拖动了对话框。
有没有办法让对话框在使用滚动条时不拖动?
我注意到有一些方法可以避免元素被拖动,但滚动条不是元素。
谢谢
编辑:JSFiddle:http://jsfiddle.net/FGXnR/
A long time ago I created a dialog box in my application. The dialog is pretty simple, position absolute, centered in the screen via javascript.
Now I have added jQuery UI to the application but I do not want to use jQuery UI's dialogs just because they work differently. But I did make my dialog draggable using jQuery UI as it is very easy:
$('#dialog').draggable();
There is one problem with that, some of my dialogs have scrollbars.
But using the draggable method, if there is a scrollbar, it bugs because it drags the dialog.
Is there a way for the dialog to not drag while using the scrollbar ?
I noticed there are some ways to avoid elements to be dragged, but scrollbars are not elements.
Thank you
EDIT: JSFiddle: http://jsfiddle.net/FGXnR/
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
作为解决方法,您可以尝试使用
handle
选项并且仅使对话框中不可滚动的部分可拖动。 (标题或类似内容。)jsFiddle 示例
@AlexFigueiredo 指出的另一个解决方案仅涉及 将内容/句柄包装在处理大小和滚动的
div
中 - 这似乎停止单击事件被发送到句柄。As a workaround, you could try using the
handle
option and only make the dialog draggable by the parts that aren't scrollable. (The title or some such.)jsFiddle Example
Another solution that @AlexFigueiredo pointed out involves just wrapping the content / handle in a
div
that handles the sizing and scrolling – that seems stop the click event from being sent to the handle.