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

房东的猫 提交于 2019-12-04 03:20:10

问题


$('#element').draggable ({
    stop: function () {
        alert ('stopped');
        //do some action here
    }
}).trigger('stop');

nothing happens, thought #element is draggable now and event does execute after drag is complete. I tried .triggerHandle as well as 'dragstop' as eventtype, no luck


回答1:


Use this to trigger it instead:

.trigger('dragstop')

If you want it to behave completely as a normal event, use .bind('dragstop', function) to attach it as well, the start option behaves slightly differently.




回答2:


I know this is an old question, but now it is possible to trigger the actual drag event of jquery ui instead of the dragstart and dragstop by using the jQuery simulate plugin.

Here is the code I used because I needed access to the snapping elements of my resizable object (data only accesible on drag stop)

$(this).resizable({
    handles: 'e',
    stop: function (e, ui) {
        var resizable = ui.element;             
        resizable.simulate("mousedown", {clientX: e.clientX, clientY: e.clientY});
        resizable.simulate("mousemove", {clientX: e.clientX + 10, clientY: e.clientY + 10});
        resizable.simulate("mouseup", {clientX: e.clientX, clientY: e.clientY});
    }
});


来源:https://stackoverflow.com/questions/3590698/jquery-triggerstop-method-for-draggable

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!