jQuery UI sortable scroll helper element offset Firefox issue

前端 未结 15 2305
故里飘歌
故里飘歌 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条回答
  •  Happy的楠姐
    2020-12-07 22:51

    I managed to figure out a fix for this:

    $( "items" ).sortable({
    start: function (event, ui) {
     if( ui.helper !== undefined )
      ui.helper.css('position','absolute').css('margin-top', $(window).scrollTop() );
    },
    beforeStop: function (event, ui) {
     if( ui.offset !== undefined )
      ui.helper.css('margin-top', 0);
    },
    placeholder: 'placeholder-class'
    });
    

    Basically, you need to listen for the sortable's "start" event to add the browser's current scrollTop() value to the helper's position, and then you need to listen for the sortable's "beforeStop" event, to remove that offset before the item is officially placed back into the list at its new position.

    Hope that's helpful to someone!

提交回复
热议问题