2017-06-12 93 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 
}); 

这样,当页面加载时执行。