当我单击画布并拖动我的鼠标时,光标变为文本选择光标。如何防止这种情况? [英] When I click on a canvas and drag my mouse, the cursor changes to a text-selection cursor. How can I prevent this?
问题描述
这里是一个小提琴: http://jsfiddle.net/MZ9Xm/
注意:以下情况发生在Chrome 22.0.1221.1中,但不在Firefox 14.0.1中。 [Ubuntu linux]
Note: The following occurs in Chrome 22.0.1221.1, but not in Firefox 14.0.1. [Ubuntu linux]
将鼠标移至顶部画布,然后按住鼠标按钮。拖动鼠标,光标将变为文本选择鼠标光标(I-bar)。如果页面上没有其他元素,则不会发生。
Move your mouse to the top canvas and press and hold the mouse button. Drag the mouse, and the cursor will change to a text-selection mouse cursor (I-bar). This does not happen if there are no other elements on the page.
我将用户选择设置为none,但没有任何运气。 / p>
I've messed around with setting user-selection to none, but have not had any luck.
推荐答案
您可以在画布中绑定一个mousedown事件,以防止默认行为。
You can bind a mousedown event in your canvas to prevent default behavior.
像:
// with jQuery
$( "#canvasId" ).mousedown(function(event){
event.preventDefault();
});
// without jQuery
document.getElementById( "canvasId" ).onmousedown = function(event){
event.preventDefault();
};
这是更新的小提琴: http://jsfiddle.net/MZ9Xm/1/
您需要进行测试,看看是否有一些副作用你在做什么。
You will need to test this to see if there is some side effect in what you are doing.
这篇关于当我单击画布并拖动我的鼠标时,光标变为文本选择光标。如何防止这种情况?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!