jquery 隐藏砌体中除第一个图像之外的所有图像

发布于 2024-12-04 18:27:56 字数 422 浏览 0 评论 0原文

我正在尝试应用此选择器来删除除第一个图像之外的所有图像,如下所示。

$(".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技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

甜扑 2024-12-11 18:27:56

在这种情况下,您需要选择整个匹配元素列表中除第一项之外的所有项目。 .slice(startIndex) 非常适合这种集合缩减,如下所示:

$(".item_cont a img").slice(1).hide();

这是你更新的jsfiddle,虽然我个人对所有图像都得到403......所以它可以't工作清晰可见。

如果我误解了,并且您想删除除第一个 per .item_cont 之外的所有内容,那么您需要的是选择器方面的更多内容,例如 :gt() (大于索引):

$(".item_cont a img:gt(0)").hide();

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:

$(".item_cont a img").slice(1).hide();

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):

$(".item_cont a img:gt(0)").hide();
忆梦 2024-12-11 18:27:56

像这样的东西吗?

var imgToKeep = $(".item_cont a img")[0];
$("img").each(function () {
    if (this !== imgToKeep) {
        $(this).hide();
    }
});

Something like this?

var imgToKeep = $(".item_cont a img")[0];
$("img").each(function () {
    if (this !== imgToKeep) {
        $(this).hide();
    }
});
通知家属抬走 2024-12-11 18:27:56

尽管它们在测试环境中确实可以工作,但无法让其中任何一个工作。我想知道是否是砖石造成了问题。

解决方法是在后端使用正则表达式在隐藏的 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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文