2013-03-27 13 views
1

7天前預期(在寫這篇文章的時間)不工作: Sortable: Incorrect behaviour (or incorrect documentation) of sortable option tolerance: 'intersect'jQuery用戶界面可排序:容忍「相交」下面的錯誤已被重新爲(BUG#8342)

可惜我不能等待jQuery來解決這個問題。

我有一個容器可以垂直分類(全部爲<div> s)。這些物品有不同的高度(並且這些高度都沒有預定義)。

有沒有一個體面的解決方法可用?

回答

1

我寫了自己的解決方法,通過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; 
       } 
      } 
     } 
    }); 
} 
+0

只是一個頭:排序被稱爲非常頻繁,所以遍歷所有容器的每個鼠標移動的孩子可能是昂貴的.. – plesatejvlk 2013-10-14 07:51:49

相關問題