开发者

Jquery - disable select when dragging

开发者 https://www.devze.com 2023-02-10 05:33 出处:网络
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开发者_运维

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

精彩评论

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