Jquery UI sortable - perform action BEFORE start event fires

后端 未结 2 2120
南旧
南旧 2021-02-07 15:52

I have searched STACKOVERFLOW and other forums for the solution to my problem - if I have missed a working solution please point me towards it.

My Problem: Whenever drag

相关标签:
2条回答
  • 2021-02-07 16:15

    I've searched a long time for this "solution":

    $('.handle').each(function() {
        $(this).mousedown(function() {
            $(this).parent().parent().children('ol').hide('blind', 500);
        });
    });
    

    You can trigger a event by mousedowning the handle and hide whatever you want. Then set the option delay of the sortable to a value greater than the duration of the hiding animation, in my example 501.

    It's not a elegant solution, but it works - at least in my program.

    0 讨论(0)
  • 2021-02-07 16:30

    You can do this, but it's not future proof for upcoming versions of jQuery UI:

    var oldMouseStart = $.ui.sortable.prototype._mouseStart;
    $.ui.sortable.prototype._mouseStart = function(event, overrideHandle, noActivation) {
       this._trigger("CustomBeforeStart", event, this._uiHash());
       oldMouseStart.apply(this, [event, overrideHandle, noActivation]);
    };
    

    You can then use the new event when setting up the sortable:

    $(".whatever").sortable({
      "CustomBeforeStart":function(e, ui) {
      }
      ...
    });
    
    0 讨论(0)
提交回复
热议问题