2015-02-12 71 views
0

我試圖添加一個類到最初的3個項目時佈局加載最初和每次它根據選定的過濾器而變化。同位素添加一個類到前3項(onload,過濾)

$container.isotope('on', 'layoutComplete', 
    function(isoInstance, laidOutItems) { 

     // no results 
     if (!laidOutItems.length) { 
      $('.message').fadeIn('slow'); 
     } else { 
      $('.message').fadeOut('fast'); 
     } 

     // add popular class to first 3 items 
     $('.item').find('.well').removeClass('popular'); 
     $('.item:lt(3)').find('.well').addClass('popular'); 
    } 
); 

以上僅影響在頁面上硬編碼的項目。我無法從佈局中的所有項目中刪除類,然後將其添加到前3個已過濾的項目中。

回答

0

您可以使用它們的類來定位隱藏的元素和可見元素。所以首先你會添加和刪除一個隱藏的類,這樣過濾的內容:

var itemReveal = Isotope.Item.prototype.reveal; 
Isotope.Item.prototype.reveal = function() { 
    itemReveal.apply(this, arguments); 
    $(this.element).removeClass('isotope-hidden'); 
}; 

var itemHide = Isotope.Item.prototype.hide; 
Isotope.Item.prototype.hide = function() { 
    itemHide.apply(this, arguments); 
    $(this.element).addClass('isotope-hidden'); 
}; 

一旦你知道什麼是可見和不可見,你將能夠使用:lt(3)').你可見項目