3

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);
Community
  • 1
  • 1
WhiteLine
  • 1,919
  • 2
  • 25
  • 53

1 Answers1

1

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>
T J
  • 42,762
  • 13
  • 83
  • 138