jQuery UI sortable scroll helper element offset Firefox issue

前端 未结 15 2202
故里飘歌
故里飘歌 2020-12-07 22:32

I have a problem with a jQuery UI 1.7.2 sortable list in Firefox 3.6, IE7-8 work fine. When I\'m scrolled down a bit, the helper element seems to have an offset of the same

15条回答
  •  时光说笑
    2020-12-07 23:00

    For future readers I ran into a similar problem where the helper element has an offset when dragging inside the scrolled div of a bootstrap dialog. When releasing the dragged object, the animation sends the dragged helper element towards it's new position without considering the scrolled portion of the page, which gives a confusing feedback to users.

    In order to keep things working with position:relative and overflow-y:auto in the dialog container, my solution was

    1- Add the scrollTop() offset to the margin-top on the helper object in the sort start event;

    2- remove the margin-top in the beforeStop event

    This fixed the animation from being off after draging, but the helper object is pushed below the cursor while dragging in the scrolled portion in the page. The last fix is

    3- Calculate and set the top property of the helper object while dragging (using the sort event) relative to the pointer and the container offset.

    $(...).sortable({
    ...
    start: function (event, ui) {  
        ui.helper.css('margin-top', $("#mybootstrap-dialog").scrollTop()); 
    },
    beforeStop: function (event, ui){ 
        ui.helper.css('margin-top',0); 
    },
    sort: function(event, ui) {
        var top = event.clientY - $('#my-sortable-ul').offset().top  -  $("#mybootstrap-dialog").scrollTop();
        ui.helper.css({'top' : top + 'px'});
        }
    },
    ...
    

    });

    Help this helps

提交回复
热议问题