开发者

Jquery - disable select when dragging

I'm trying to do my own drag and drop function using jquery library. But everytime I mousedown on an image, then mousemove, my browser "highlights" or "selects" the image, which disrupt开发者_运维技巧s my mousemove operation.

How do I disable the select/highlight? I tried $('img').onselectstart = function() {return false;}, but that didn't work.


You could prevent the default behaviour of the dragstart event...

$('img').bind('dragstart', function(event) { event.preventDefault(); });

jsFiddle.


jQuery UI has an undocumented method that it uses to disable browser text selection. You can call it using this syntax:

$('IMG').disableSelection();

Remember that you need to be using jQuery UI (which I assume you are).

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜