Search code examples
javascriptjquerydrag-and-dropdrag

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.


Solution

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

    Refer HTML Drag and Drop API for all the events.

    $('#image').on('dragstart', function(event) {
      console.log('dragstart');
    });
    $('#image').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="https://www.repeatsoftware.com/Help/img3C.gif" id="image" height="100px" width="100px" />