1

9 日前 (この記事の執筆時点) に、次のバグが再び 公開されました。

残念ながら、jQuery がこの問題を修正するのを待ちきれません。

垂直方向に並べ替えることができるアイテムを含む単一のコンテナーがあります (すべて<div>s)。これらのアイテムは高さが異なります (これらの高さは事前定義されていません)。

利用可能な適切な回避策はありますか?

4

1 に答える 1

2

dioslaskaの彼自身の質問に対する解決策 に触発されて、自分で回避策を書きました: jQuery UI sortable tolerance option not working as expected

それは非常にスムーズに動作します:)

オプションを削除しtolerance、次の関数をsortオプションとして使用します。

function( e, ui ) {
    var container   = $( this ),
        placeholder = container.children( '.ui-sortable-placeholder:first' );

    var helpHeight  = ui.helper.outerHeight(),
        helpTop     = ui.position.top,
        helpBottom  = helpTop + helpHeight;

    container.children().each( function () {
        var item = $( this );

        if( !item.hasClass( 'ui-sortable-helper' ) && !item.hasClass( 'ui-sortable-placeholder' )) {
            var itemHeight = item.outerHeight(),
                itemTop    = item.position().top,
                itemBottom = itemTop + itemHeight;

            if(( helpTop > itemTop ) && ( helpTop < itemBottom )) {
                var tolerance = Math.min( helpHeight, itemHeight ) / 2,
                    distance  = helpTop - itemTop;

                if( distance < tolerance ) {
                    placeholder.insertBefore( item );
                    container.sortable( 'refreshPositions' );
                    return false;
                }

            } else if(( helpBottom < itemBottom ) && ( helpBottom > itemTop )) {
                var tolerance = Math.min( helpHeight, itemHeight ) / 2,
                    distance  = itemBottom - helpBottom;

                if( distance < tolerance ) {
                    placeholder.insertAfter( item );
                    container.sortable( 'refreshPositions' );
                    return false;
                }
            }
        }
    });
}
于 2013-03-27T16:27:42.453 に答える