2017-06-12 135 views
0

我想在加載頁面時顯示預先選擇的過濾器。同位素過濾效果很好,過濾器可以應用,但我不想在加載頁面時看到「全部」,所以我試圖在代碼中添加預先選定的過濾器。我究竟做錯了什麼?同位素過濾器:加載過濾器

$('body').on('click touchstart', 'section.gallery .gallery-filters .filter', function(event) { 

    event.preventDefault(); 

    var isotope = $(this).parent().parent(); 
    var isotopeID = isotope.data('isotope-id'); 
    var filterValue = $(this).data('filter'); 


    martanianLuxuryApartmentsIsotopes[isotopeID].isotope({ filter: filterValue }); 

    isotope.find('.gallery-filters').children('.filter').removeClass('filter-active'); 
    $(this).addClass('filter-active'); 

      //SHOW THE SELECTED FILTER 
    isotope({ 
    itemSelector: '.filter', 
    filter: '.gallery-filter-building' 
    }); 

    isotope.find('.gallery-single-image').removeClass('isotope-element-visible'); 
    var filteredElements = martanianLuxuryApartmentsIsotopes[isotopeID].isotope('getFilteredItemElements'); 
    for(var i = 0; i < filteredElements.length; i++) { 

     var filteredElement = $(filteredElements[i]); 
     filteredElement.addClass('isotope-element-visible'); 

    }; 

}); 

回答

0

我建議你使用所有的功能在這裏面

$(function() { 
    //all code isotope here 
}); 

或等於

$(document).ready(function() { 
    //all code isotope here 
}); 

這樣,當頁面加載時執行。