[英]Isotope filters: filter on load
我想在加載頁面時顯示預選的過濾器。 同位素過濾效果很好,過濾器確實適用,但是加載頁面時我不想看到“全部”,所以我試圖在代碼中添加預選的過濾器。 我究竟做錯了什么?
$( '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' );
};
});
我建議你用這個
$(function() {
//all code isotope here
});
或相等
$(document).ready(function() {
//all code isotope here
});
這樣,頁面加載時將執行該函數中的所有內容。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.