JQueryUI Draggable, fires "stop" event
The object I have to drag can also be moved by the keyboard event (key up, down, left and up)
In the drag event of any object, I have a function that does something, and when the object is moved from the keyboard, I have to trigger the drag stop event
All these solutions don't work
JQuery.trigger ('stop') method for .draggable
$("#obj").draggable().trigger("dragstop");
$("#obj").trigger("dragstop");
How to use trigger to run jquery draggable start, drag, stop events?
var s = [{ClientX:0, ClientY:0, target:""},{}];
$("#obj").draggable("option" , "stop").apply($("#obj") , s);
+3
source to share
1 answer
I believe you bind the event stop
(or whatever) on initialization like this:
$("#draggable").draggable({
stop: function(ev,ui){
}
});
In this case, trigger
it will not work.
Bind the event separately,
eg:
$("#draggable").on("dragstop",function(ev,ui){
});
Then the trigger is fired.
$("#draggable").draggable();
$("#draggable").on("dragstop", function(ev, ui) {
alert("draggable stop");
});
$("button").click(function(){
$("#draggable").trigger("dragstop");
});
#draggable {
width: 50px;
height: 50px;
background: dodgerblue;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<script src="//code.jquery.com/ui/1.11.2/jquery-ui.js"></script>
<div id="draggable"></div>
<button>click</button>
+1
source to share