如何防止文本和/或页面内容在 html 和 javascript 中双击突出显示? [英] How do I prevent text and/or page content double-click highlighting in html and javascript?

查看:29
本文介绍了如何防止文本和/或页面内容在 html 和 javascript 中双击突出显示?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有点奇怪的问题,但我正在为万圣节派对制作一个游戏.用于快速和肮脏的开发的 Javascript/HTML.(这将在投影仪上全屏显示并使用 Wiimote 进行鼠标控制).这就是我正在使用的,我的问题不是要引起对我的代码选择的批评.效果很好,除了一件事.

Kind of an odd question, but I have a game I am making for a Halloween party. Javascript/HTML for quick and dirty development. (This is going to be full screen on a projector and use a Wiimote for mouse control). This is what I am using, my question is not intended to invoke criticism of my code choice. It works great, except for one thing.

基本上,这是一个射击场/导弹指挥风格的游戏,您需要在物体在屏幕上移动时点击或射击它们.我有用于单击对象的 onmousedown 处理程序.但是,当您双击(即快速触发)时,该对象会被突出显示,如果您错过了该对象,则同一 div 中包含的其他对象也会被突出显示.为了解决这个问题,在 mousedown 处理程序中,我设置了焦点/选择了一个不在页面上的文本框.这在一定程度上是有效的,因为对象不会保持突出显示,但它们会在失去焦点之前短暂突出显示.

Basically, it is a shooting gallery/missile command style game where you need to click on or shoot objects as they move across the screen. I have onmousedown handlers for clicking on the objects. However, when you double click, i.e. fire rapidly, the object gets highlighted, as well as the other objects contained in the same div if you miss the object. To solve this, in the mousedown handler, I set focus/select a text box that is off of the page. This works to some extent, as the objects do not remain highlighted, but they do get highlighted briefly before they lose focus.

简而言之,有没有更好的方法来防止双击对我的页面产生这种影响?

In short, is there a better way to prevent double-click from having this affect on my page?

推荐答案

来自:Prevent双击后选择文本

* {
     -moz-user-select: none; // mozilla browsers
     -khtml-user-select: none; // webkit browsers
}

这篇关于如何防止文本和/或页面内容在 html 和 javascript 中双击突出显示?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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