我必须拖动的对象也可以通过键盘事件(键向上,向下,向左和向上)移动
在任何对象的拖动事件中,我有一个功能可以执行某些操作,当键盘移动对象时,我必须调用拖动停止事件
所有这些解决方案都不起作用
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);
答案 0 :(得分:1)
我相信您在初始化时绑定了stop
(或任何其他)事件,如下所示:
$("#draggable").draggable({
stop: function(ev,ui){
}
});
在这种情况下,trigger
无法正常工作。
单独绑定事件,
例如:
$("#draggable").on("dragstop",function(ev,ui){
});
然后触发将起作用。
$("#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>
&#13;