Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

jQueryUI Draggable , trigger the "stop" event

The object that i must drag can also be moved by the event of the keyboard (key up , down , left and top)

In the drag event of any object i have a function that do something , and when the object is moved by the keyboard i must call the drag stop event

All of this solutions doesn't work

Jquery .trigger('stop') method for .draggable

$("#obj").draggable().trigger("dragstop");

$("#obj").trigger("dragstop");

How would you use Trigger to fire the jquery draggable start, drag, stop events?

var s = [{ClientX:0, ClientY:0, target:""},{}];
$("#obj").draggable("option" , "stop").apply($("#obj") , s);
like image 511
WhiteLine Avatar asked May 17 '26 15:05

WhiteLine


1 Answers

I believe you're binding the stop (or any other) event while initializing as follows:

$("#draggable").draggable({
 stop: function(ev,ui){
 }
});

In that case, trigger won't work.

Bind the event separately,

for example:

$("#draggable").on("dragstop",function(ev,ui){

});

Then trigger will work.

$("#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>
like image 149
T J Avatar answered May 20 '26 06:05

T J



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!