2016-10-01 24 views
0

使用JQuery識別dragstart和dragstop。 dragstart事件工作正常,但dragstop事件沒有。 下面是代碼我wrote-JQuery上的Dragstop

$('img').on('dragstart', function (event) { 
 
\t $(function() { \t \t  
 
      $("#toolbar").animate({width:'toggle'},0);  
 
\t \t }); 
 
\t \t 
 
}); 
 
$('img').on('dragstop', function (event) { 
 
\t \t alert("hi"); \t 
 
});

感謝。

回答

0

使用dragend事件! 當拖動操作正在結束

參考HTML Drag and Drop API所有的事件觸發。

$('img').on('dragstart', function(event) { 
 
    $(function() { 
 
    console.log('dragstart'); 
 
    }); 
 

 
}); 
 
$('img').on('dragend', function(event) { 
 
    console.log('dragend'); 
 
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.0/jquery.min.js"></script> 
 
<img src="http://ultraimg.com/images/2016/07/29/Simplest-Responsive-jQuery-Image-Lightbox-Plugin-simple-lightbox.jpg" id="image" height="100px" width="100px" />