bbtron bbtron - 2 months ago 26
jQuery Question

Dragstop on JQuery

Im using JQuery for recognizing dragstart and dragstop.
The dragstart event is working perfectly but the dragstop event doesn't.
Here is the code i wrote-



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

});
$('img').on('dragstop', function (event) {
alert("hi");
});





Thanks.

Answer

Use dragend event! Fired when a drag operation is being ended

Refer HTML Drag and Drop API for all the events.

$('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" />