如何禁用select为html5 canvas元素 [英] How to disable select for html5 canvas element

查看:391
本文介绍了如何禁用select为html5 canvas元素的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在html5画布中监听点击事件,它的工作正常。但是,当我点击图片上的任何位置时,浏览器会将其突出显示,就好像它被选中一样(类似于图片在页面上点击时的高亮显示方式)。我很好奇,如果有人知道如何禁用选择的html元素,如画布。

I listen for click events inside an html5 canvas and it works just fine. However, when I click anywhere on the image the browser highlights it as if it were selected (similar to how an image might look highlighted if clicked on a page). I was curious if anyone knew how to disable selecting of html elements such as canvas. I don't want the canvas to appear outlined when someone clicks it.

推荐答案

您可以尝试沿着这些CSS规则应用一些CSS规则:

You could try applying a few CSS rules along these:

user-select: none;
-webkit-user-select: none;
-moz-user-select: none;

正如迈克尔提到的jQuery的disableTextSelect值得一试。即使你最终不会使用它,学习来源可能会有一些洞察力。

As Michael mentioned jQuery's disableTextSelect is worth checking out. Even if you don't end up using it, studying the source might give some insight.

这篇关于如何禁用select为html5 canvas元素的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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