最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - How to disable dragging with mouse click any images? - Stack Overflow

programmeradmin4浏览0评论

I have an image <img src="fullscreen.jpg" /> for online driving exams, where the questions are asked using image text and with image embedded. When anyone click the image and drag the mouse it moves the image.

But how can i stop this dragging? So that nobody is allowed to do so.

I have an image <img src="fullscreen.jpg" /> for online driving exams, where the questions are asked using image text and with image embedded. When anyone click the image and drag the mouse it moves the image.

But how can i stop this dragging? So that nobody is allowed to do so.

Share Improve this question asked Sep 29, 2011 at 23:26 user285594user285594
Add a ment  | 

3 Answers 3

Reset to default 7
$('#id-of-your-image').mousedown(function(){return false});

Of course you may have to use other selector as in your example image has no id attribute.

If you're using jQuery, you're looking for the dragstart event.

$("img").bind('dragstart', function(){
    return false; 
});

Try any of these 3 if you can't or don't want to use an id or jQuery (cross-browser performance has not been tested):

<img src="http://www.google./intl/en_/images/srpr/logo3w.png" ondragstart='return false;'/>
<img src="http://www.google./intl/en_/images/srpr/logo3w.png" onmousedown='return false;'/>
<img src="http://www.google./intl/en_/images/srpr/logo3w.png" onmousedown='return false;' ondragstart='return false;'/>

Demo

发布评论

评论列表(0)

  1. 暂无评论