同位素过滤器:负载过滤

时间:2017-06-12 11:15:06

标签: javascript isotope

我想在加载页面时显示预先选择的过滤器。同位素过滤效果很好,过滤器确实适用,但我不想在加载页面时看到“全部”,所以我试图在代码中添加预先选择的过滤器。我做错了什么?

$( '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' );

    };

});

1 个答案:

答案 0 :(得分:0)

我建议你使用这个

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

或等于

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

这样,当页面加载时,该函数内部都会执行。