简体   繁体   English

jQueryUI可拖动,触发“停止”事件

[英]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 .draggable的Jquery .trigger('stop')方法

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

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

How would you use Trigger to fire the jquery draggable start, drag, stop events? 你将如何使用Trigger来触发jquery draggable start,drag,stop events?

var s = [{ClientX:0, ClientY:0, target:""},{}];
$("#obj").draggable("option" , "stop").apply($("#obj") , s);

I believe you're binding the stop ( or any other ) event while initializing as follows: 我相信你在初始化时绑定了stop或任何其他 )事件,如下所示:

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

In that case, trigger won't work. 在这种情况下, trigger将无法工作。

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> 

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM