为什么不推荐使用.disableSelection()? [英] Why is .disableSelection() deprecated?

查看:127
本文介绍了为什么不推荐使用.disableSelection()?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

JQueryUI 1.9中的

.disableSelection已弃用.从字面上看,我能找到的唯一解释是禁用文本选择很糟糕.请不要使用它." >我们不应允许开发人员弄乱文本选择.最初是用于交互插件的,但是他们现在都自行处理了正确的文本选择."

由于没有其他建议,因此我认为它们的意思是总是,但是我无法理解他们的原因.双击/三次单击或以其他方式无意义地选择精致的UI应用程序将不适当地应用文本突出显示效果,并且(对我而言)立即消除了强大的用户体验的幻觉.

桌面应用程序不受此困扰!桌面环境中的按钮和其他控件是像素区域,无论您对它们进行什么操作(否则它们都坏了),它们看起来都是稳定且直观的. Web应用程序由复杂的html框,背景,边框和图像(像素的网络模拟)组成,这一事实没有理由背叛我们与之交互的屏幕元素不是原子的物理对象的错觉. /p>

在下图中,可以说某些文本应该是可选的,例如面板中的文本段落可能是应用程序数据.但是对于某些应用程序来说,合理的设计选择是其他部分(例如按钮,选项卡,手风琴标题和模态对话框后面的文本)无法选择的.这尤其适用于可拖动/可分类的行为.

1)我是否误解了他们的决定?推荐是否比我意识到的更具体地针对JQuery?

2)如果一般性地说应该这样选择文本始终,请提供原因的完整说明.

3)如果我仍然要这样做,那么现在不推荐使用disableSelection是最高效,完整,尊重,跨浏览器并且可以普遍使用的功能吗?

解决方案

您可以使用CSS在大多数浏览器中完成此操作: http://jsfiddle.net/fQthQ/

* {
   -ms-user-select: none; /* IE 10+ */
   -moz-user-select: -moz-none;
   -khtml-user-select: none;
   -webkit-user-select: none;
   user-select: none;
}

.selectable {
   -ms-user-select: auto;
   -moz-user-select: auto;
   -khtml-user-select: auto;
   -webkit-user-select: auto;
   user-select: auto;
}

Opera当前不支持此功能.

有关更多信息,请参见MDN页面: https://developer. mozilla.org/zh-CN/docs/CSS/user-select

.disableSelection in JQueryUI 1.9 is deprecated. The only explanation I can find is, literally, "Disabling text selection is bad. Don't use this." and "We shouldn't allow developers to mess with text selection. This was originally for the interaction plugins, but they're all handling text selection properly on their own at this point."

Since there is no alternative suggested, I assume they mean that it is always bad but I cannot fathom their reasons. A double/triple-click or otherwise meaningless selection of an elaborate-UI application improperly applies the text-highlight effect and (to me) instantly removes the illusion of a robust user experience.

Desktop applications don't suffer from this! Buttons and other controls in a Desktop environment are regions of pixels that look solid and act intuitively no matter what you do to them (or else they're broken). The fact that web applications are composed of complex html boxes, backgrounds, borders, and images (the web-analog of pixels) is no reason to betray the illusion that the screen elements we interact with isn't an atomic, physical object.

In the image below, arguably some of the text should be selectable, such as the paragraphs of text within panels which could be application data. But for some applications it would be a reasonable design choice that other parts, such as the text in buttons, tabs, accordion headers, and text behind modal dialogs would not be selectable. This especially applies to draggable/sortable kinds of behaviors.

1) Am I misinterpreting their decision? Is the recommendation more specific to JQuery than I realize?

2) If it is meant as a general statement that text should always be selectable like this, please provide a fuller explanation of why.

3) If I were going to do it anyway, what is the most performant, complete, respectful, cross-browser, and universally accessible to go about it now that disableSelection is deprecated?

解决方案

You can use CSS to accomplish this in most browsers: http://jsfiddle.net/fQthQ/

* {
   -ms-user-select: none; /* IE 10+ */
   -moz-user-select: -moz-none;
   -khtml-user-select: none;
   -webkit-user-select: none;
   user-select: none;
}

.selectable {
   -ms-user-select: auto;
   -moz-user-select: auto;
   -khtml-user-select: auto;
   -webkit-user-select: auto;
   user-select: auto;
}

Opera does not currently support this feature.

See the MDN page for more info: https://developer.mozilla.org/en-US/docs/CSS/user-select

这篇关于为什么不推荐使用.disableSelection()?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆