简体   繁体   English

jQuery Isotope第一次过滤似乎不起作用

[英]jQuery Isotope first filtering doesn't seem to work

I'm facing an issue here. 我在这里面临一个问题。 I'm using a similar code for filtering in two pages 我正在使用类似的代码在两页中进行过滤

$('#filter a')[<number>].click() is the triggering mechanism. $('#filter a')[<number>].click()是触发机制。 On page load it is triggered after 10 seconds automatically or can be manually intervened before 10 seconds 在页面加载时,它会在10秒后自动触发,也可以在10秒前手动进行干预

When the page(s) loads a default set of items in $('.portfolio_block') are shown and the rest are display:none 当页面加载时,将显示$('.portfolio_block')中的默认项目集,其余display:none

On the first page, the first filtering works properly. 在第一页上,第一个过滤器正常工作。 Items are added in filteredItems, elements are hidden, animation shows up and elements are displayed. 将项目添加到filteredItems中,将元素隐藏,显示动画并显示元素。 No problems here 这里没问题

But on the second page, items are added and elements are hidden. 但是在第二页上,项目被添加,元素被隐藏。 Mechanism stops here. 机制到此为止。 This only happens on the first trigger. 这仅在第一个触发器上发生。 From the second trigger on wards, it goes back to functioning properly. 从第二个触发器开始,它会恢复正常运行。

$('.portfolio_block').isotope({ filter: $(this).attr('data-option-value')}) that's how I'm using isotope. $('.portfolio_block').isotope({ filter: $(this).attr('data-option-value')})这就是我使用同位素的方式。

Any help will be great. 任何帮助都会很棒。

PS I've tried using $('.portfolio_block').isotope() but it just messes up the layout on page load. PS我试过使用$('.portfolio_block').isotope()但它只会弄乱页面加载时的布局。

PPS I've added console logging of isotope data for debugging purposes. PPS我添加了同位素数据的控制台日志记录,以用于调试目的。

Isotope - http://isotope.metafizzy.co/filtering.html 同位素-http: //isotope.metafizzy.co/filtering.html

Surprisingly or unknowingly, jquery-isotope has to be initiated with all the elements before anything. 出人意料的是,必须在所有元素之前启动jquery-isotope。 Adding the following on document ready fixes the problem. 在准备就绪的文档上添加以下内容可解决此问题。

var $portfolioBlock = $('.portfolio_block').isotope({
   itemSelector: '<common_class_for_all_elements_requiring_isotope>',
   filter: '<initial_filtering_class>'
});

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM