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

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

问题描述:

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

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.

这是一个jsfiddle,您可以在其中重现该问题: http://jsfiddle.net/dmosher/8ZGLR/

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

disableSelection是您的朋友在这里.

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.

您可能想要创建一个帮助程序,以便看起来有些东西被拖了.

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

更新了演示