jquery 隐藏砌体中除第一个图像之外的所有图像
我正在尝试应用此选择器来删除除第一个图像之外的所有图像,如下所示。
$(".item_cont a img").not(":eq(0)").hide();
如下所示:
http://jsfiddle.net/jojoroxursox/9AFpv/
但是应用于砖石时grid 它会删除所有项目,甚至是那些只有一张图像的项目。
http://jsfiddle.net/jojoroxursox/M9Yau/
有什么建议吗?
I'm trying to apply this selector to remove all images other than the first in a div that looks like this.
$(".item_cont a img").not(":eq(0)").hide();
as shown here:
http://jsfiddle.net/jojoroxursox/9AFpv/
however when applied to a masonry grid it removes all items, even the ones that only have one image.
http://jsfiddle.net/jojoroxursox/M9Yau/
any suggestions?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
![扫码二维码加入Web技术交流群](/public/img/jiaqun_03.jpg)
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
在这种情况下,您需要选择整个匹配元素列表中除第一项之外的所有项目。
.slice(startIndex)
非常适合这种集合缩减,如下所示:这是你更新的jsfiddle,虽然我个人对所有图像都得到403......所以它可以't工作清晰可见。
如果我误解了,并且您想删除除第一个 per
.item_cont
之外的所有内容,那么您需要的是选择器方面的更多内容,例如:gt()
(大于索引):In this case you'd want to select all but the first item in the matched element list overall.
.slice(startIndex)
is perfect for this set reduction, like so:Here is your updated jsfiddle, though I personally get 403s for all images...so it can't be seen working clearly.
If I misunderstood and you want to remove all but the first per
.item_cont
, what you'll want is something more on the selector side, like:gt()
(greater than index):像这样的东西吗?
Something like this?
尽管它们在测试环境中确实可以工作,但无法让其中任何一个工作。我想知道是否是砖石造成了问题。
解决方法是在后端使用正则表达式在隐藏的 div 中输出第二级图像。
Couldnt get any of these to work, enven though they definitely work in test environments. I wonder if its masonry thats creating the problem.
the workaround was to use regex in the backend to output the 2nd level of images in a hidden div.