2013-02-10 2 views
3

다른 항목의 크기를 변경 한 후 작은 항목을 빈 칸으로 옮기고 싶습니다.jQuery 동위 원소에서 reLayout 이후에 작은 항목을 빈 공간에 맞 춥니 다

이는 jsfiddle에 모습입니다 : http://jsfiddle.net/FRH8v/

예를 들어 더 클릭하지 않을 때. 2, 그 위에 두 개의 빈 공간이 생깁니다. 그 공간을 채우기 위해 작은 항목을 이동하는 방법? 여기

코드 (jsfiddle에 같은 동일)입니다 :

$(function(){ 
    // Modified Isotope methods for gutters in masonry 
    $.Isotope.prototype._getMasonryGutterColumns = function() { 
     var gutter = this.options.masonry && this.options.masonry.gutterWidth || 0; 
     containerWidth = this.element.width(); 

     this.masonry.columnWidth = this.options.masonry && this.options.masonry.columnWidth || 
     // Or use the size of the first item 
     this.$filteredAtoms.outerWidth(true) || 
     // If there's no items, use size of container 
     containerWidth; 

     this.masonry.columnWidth += gutter; 

     this.masonry.cols = Math.floor((containerWidth + gutter)/this.masonry.columnWidth); 
     this.masonry.cols = Math.max(this.masonry.cols, 1); 
    }; 

    $.Isotope.prototype._masonryReset = function() { 
     // Layout-specific props 
     this.masonry = {}; 
     // FIXME shouldn't have to call this again 
     this._getMasonryGutterColumns(); 
     var i = this.masonry.cols; 
     this.masonry.colYs = []; 
     while (i--) { 
      this.masonry.colYs.push(0); 
     } 
    }; 

    $.Isotope.prototype._masonryResizeChanged = function() { 
     var prevSegments = this.masonry.cols; 
     // Update cols/rows 
     this._getMasonryGutterColumns(); 
     // Return if updated cols/rows is not equal to previous 
     return (this.masonry.cols !== prevSegments); 
    }; 

    var $container = $('#container'), 
     $element = '.element'; 

    $container.isotope({ 
     itemSelector: $element, 
     resizable: false, 
     transformsEnabled: true, 
     animationEngine: 'best-available', 
     layout: 'masonry', 
     masonry: { 
      gutterWidth: 4, 
      columnWidth: 157 
     } 
    }); 

    // click action 
    $container.find($element).each(function(){ 
     var that = $(this); 

     that.click(function(){ 
      if(that.hasClass('active')){ 
       $container.find($element).removeClass('active'); 
      } else { 
       $container.find($element).removeClass('active'); 
       that.addClass('active'); 
      } 

      $container.isotope('reLayout'); 

      return false; 
     }); 
    }); 
}); 

답변

0

음, 어떻게 동위 원소/벽돌 작품입니다.

저는 가능한 한 모든 "구멍"을 제거하지 않습니다. 내 경험에 비추어 볼 때, 동위 원소/벽돌은 타일을 밀어 올리지만 타일 위로 뛰어 넘지 않는다고 말할 수 있습니다. 당신의 바이올린,에서

는 5

왜에 "뛰어 넘다"이 때문에 "5", "7", 올라갈하지 않습니다 확대? 나는 정확하게 모른다. 그러나 나는 두 가지 이유를 상상할 수있다 :

: 여기에 대한 추가 정보를 원하시면 -

  • 그것은 계산의 복잡성을 감소