jquery同位素过滤
我正在尝试用同位素过滤物品。这些项目位于不同的 div 中,但由于某种原因,过滤器仅适用于第一个 div。这是我的代码:
<div id="articles">
<div class="article-wrap">
<div class="article cat-1"></div>
<div class="article cat-2"></div>
<div class="article cat-3"></div>
...
</div>
<div class="article-wrap">
<div class="article cat-1"></div>
<div class="article cat-2"></div>
<div class="article cat-3"></div>
...
</div>
</div>
我的 javascript:
$(document).ready(function() {
$('#articles .article-wrap').isotope( 'reloadItems' ).isotope({sortBy: 'class'});
$('#filters li a').click(function(){
var selector = $(this).attr('data-filter');
$('#articles .article-wrap').isotope({ filter: selector });
return false;
});
});
我做错了什么?
预先感谢
毛罗
I'm trying to filter items with isotope. These items are inside in different divs, but for some reason the filter works only for the first div. here's my code:
<div id="articles">
<div class="article-wrap">
<div class="article cat-1"></div>
<div class="article cat-2"></div>
<div class="article cat-3"></div>
...
</div>
<div class="article-wrap">
<div class="article cat-1"></div>
<div class="article cat-2"></div>
<div class="article cat-3"></div>
...
</div>
</div>
my javascript:
$(document).ready(function() {
$('#articles .article-wrap').isotope( 'reloadItems' ).isotope({sortBy: 'class'});
$('#filters li a').click(function(){
var selector = $(this).attr('data-filter');
$('#articles .article-wrap').isotope({ filter: selector });
return false;
});
});
What am I doing wrong?
Thanks in advance
Mauro
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
有了完整的代码,回答这个问题就更容易了。
您当前的代码缺少过滤器链接
$('#filters li a')
,问题可能只是您忘记在选择器前面添加.
。另外,如果这是您的全部 JavaScript,则您正在以错误的顺序调用 isotope,即您试图在初始化 isotope 之前重新加载项目。
更正后的 JS 如下所示:
我已经设置了 一个工作 jsFiddle 来向您展示结果。
With the complete code it would be easier to answer this.
Your current code is missing the filters links
$('#filters li a')
and the problem could simply be you are forgetting to add a.
to the front of your selector.Also, if this is all of your javascript, you are calling isotope in the wrong order, i.e. you are trying to reload the items before you have initialized isotope.
The corrected JS looks like this:
I've set up a working jsFiddle to show you the result.