javascript 使用jQuery UI Draggable,如何在使用滚动条时避免拖动?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/8793236/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-26 04:35:57  来源:igfitidea点击:

Using jQuery UI Draggable, how to avoid drag when using scrollbar?

javascriptjqueryjquery-uimodal-dialogdraggable

提问by Andrei

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.

很久以前,我在我的应用程序中创建了一个对话框。该对话框非常简单,位置绝对,通过 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:

现在我已经向应用程序添加了 jQuery UI,但我不想仅仅因为它们的工作方式不同而使用 jQuery UI 的对话框。但是我确实使用 jQuery UI 使我的对话框可拖动,因为它非常简单:

$('#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.

有一个问题,我的一些对话框有滚动条。
但是使用draggable方法,如果有滚动条,会因为拖拽对话框而报错。

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/

编辑:JSFiddle:http: //jsfiddle.net/FGXnR/

采纳答案by millimoose

As a workaround, you could try using the handleoptionand only make the dialog draggable by the parts that aren't scrollable. (The title or some such.)

作为一种解决方法,您可以尝试使用该handle选项并仅使对话框可被不可滚动的部分拖动。(标题或一些类似的。)

jsFiddle Example

jsFiddle 示例

Another solution that @AlexFigueiredo pointed out involves just wrapping the content / handle in a divthat handles the sizing and scrolling – that seems stop the click event from being sent to the handle.

@AlexFigueiredo 指出的另一个解决方案是将内容/句柄包装在div处理大小和滚动的 a 中——这似乎阻止了单击事件发送到句柄。