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

前端 未结 2 709
盖世英雄少女心
盖世英雄少女心 2021-01-18 09:25
$(\'#element\').draggable ({
    stop: function () {
        alert (\'stopped\');
        //do some action here
    }
}).trigger(\'stop\');

nothing

相关标签:
2条回答
  • 2021-01-18 09:56

    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});
        }
    });
    
    0 讨论(0)
  • 2021-01-18 10:00

    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.

    0 讨论(0)
提交回复
热议问题