javascript--拖動圖片時取消瀏覽器默認

拖動的問題,在網上有不少插件,但鼠標在圖片上拖動一小段距離,就會在鼠標旁邊出現一個禁止的小提示。this

解決若是點擊在圖片上沒法拖拽的問題:spa

IE經過ev.cancelBubble=true;ev.returnValue = false;來防止圖片的事件,注意是放在document.onmousemove中。要用原生的JS,不能用JQUERY!插件

FireFox經過ev.preventDefault();ev.stopPropagation(); 可是是放在titleBar的mousedown事件中。code

 1 $(function(){
 2     var $img = $("img");
 3     var moving = function(event){
 4         //..........
 5     }
 6     
 7     //IE下須要在document的mousemove裏面取消默認事件;要用原生JS的事件不能用JQuery
 8     document.onmousemove = function(e){
 9         var ev = e || event;
10         ev.cancelBubble=true;
11         ev.returnValue = false;
12     }
13     
14     $img.mousedown(function(event){
15         //FF下須要在mousedown取消默認操做;
16         event.preventDefault();
17         event.stopPropagation();
18         $(this).bind("mousemove",moving);    
19     })
20 })
相關文章
相關標籤/搜索