你怎么能以编程方式触发jQuery UI中的draggable?

时间:2012-10-27 22:17:42

标签: jquery-ui

只需拨打.trigger(“mousedown”);不起作用。

scrollPane_Y.draggable({
    axis: "y",
    stop: function (event, ui) { 
        /*
        i get triggered when the containment is hit
        so if a user hits the containment and then
        goes in the other direction nothing happens.
        */
         scrollPane_Y.trigger("mousedown"); // doesnt work
         scrollPane_Y.mousedown(function (e) { // from third link. doesnt work
             scrollPane_Y.trigger(e);
         });
    },
    containment: [0, min_scrollPane_Y, 0, max_scrollPane_Y]
});

1 个答案:

答案 0 :(得分:0)

您可以使用正确的参数直接调用其私有方法。

scrollPane_Y.draggable({
    axis: "y",
    stop: function (event, ui) { 
        /*
        i get triggered when the containment is hit
        so if a user hits the containment and then
        goes in the other direction nothing happens.
        */

         // retrieve the instance and call its private method
         scrollPane_Y.data("ui-draggable")._mouseDown(event);
    },
    containment: [0, min_scrollPane_Y, 0, max_scrollPane_Y]
});