如何在使用jQuery UI .draggable时禁用webkit浏览器中的文本选择?

时间:2022-12-20 20:38:28

I can't seem to disable text-selection in webkit browsers when using jQuery UI .draggable(). I've tried using the webkit specific css (-webkit-user-select and -webkit-user-drag) in various combinations but haven't had any luck.

在使用jQuery UI .draggable()时,我似乎无法在webkit浏览器中禁用文本选择。我尝试过各种组合使用webkit特定的css(-webkit-user-select和-webkit-user-drag),但没有运气。

Here's a jsfiddle where you can reproduce the problem: http://jsfiddle.net/dmosher/8ZGLR/

这里有一个jsfiddle,你可以重现这个问题:http://jsfiddle.net/dmosher/8ZGLR/

1 个解决方案

#1


2  

disableSelection is your friend here.

disableSelection是你的朋友。

.disableSelection() is an undocumented (for now) core utility. It's useful for making text elements, or elements that contain text, not text-selectable. For example, if you have a draggable element, you may not want text selection to occur when the user goes to drag the element.

.disableSelection()是一个未记录的(现在)核心实用程序。它对于创建文本元素或包含文本的元素非常有用,而不是文本可选择的。例如,如果您有一个可拖动元素,则在用户拖动元素时可能不希望发生文本选择。

You may want to create a helper so it looks obvious that something is being dragged.

您可能想要创建一个帮助器,因此看起来很明显正在拖动某些东西。

Updated demo

#1


2  

disableSelection is your friend here.

disableSelection是你的朋友。

.disableSelection() is an undocumented (for now) core utility. It's useful for making text elements, or elements that contain text, not text-selectable. For example, if you have a draggable element, you may not want text selection to occur when the user goes to drag the element.

.disableSelection()是一个未记录的(现在)核心实用程序。它对于创建文本元素或包含文本的元素非常有用,而不是文本可选择的。例如,如果您有一个可拖动元素,则在用户拖动元素时可能不希望发生文本选择。

You may want to create a helper so it looks obvious that something is being dragged.

您可能想要创建一个帮助器,因此看起来很明显正在拖动某些东西。

Updated demo