JQuery 可见选择器和 prev()

发布于 2024-11-02 19:43:04 字数 438 浏览 9 评论 0原文

我试图确定具有特定类的哪个元素是可见的。然后找到它的前一个元素并滑到它上面。我尝试了这个,但它不正确。

if($('#sidepanel1').is(':visible')) {
         }
        else { 

        var prevpanel = $('.sidewrapper').is(':visible').prev().attr('id'); alert(prevpanel);

        $('.sidewrapper').hide("slide", { direction: "right" }, 300); $(prevpanel).show("slide", { direction: "left" }, 300);
        }

}

这与我使用 :visible 有关,我认为这是错误的。有什么想法吗?

奇妙

I am trying to determine which element with a particular class is visible. Then find its immediate previous element and slide over to it. I tried this but it is not correct.

if($('#sidepanel1').is(':visible')) {
         }
        else { 

        var prevpanel = $('.sidewrapper').is(':visible').prev().attr('id'); alert(prevpanel);

        $('.sidewrapper').hide("slide", { direction: "right" }, 300); $(prevpanel).show("slide", { direction: "left" }, 300);
        }

}

Its something to do with my use of :visible that I think is wrong. Any ideas?

Marvellous

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

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

评论(3

海拔太高太耀眼 2024-11-09 19:43:04

更改

var prevpanel = $('.sidewrapper').is(':visible').prev().attr('id');

var prevpanel = $('.sidewrapper:visible').prev().attr('id');

.is() 返回 bool

与其他过滤方法不同,.is() 不会创建新的 jQuery 对象。相反,它允许您无需修改​​即可测试 jQuery 对象的内容。

change

var prevpanel = $('.sidewrapper').is(':visible').prev().attr('id');

to

var prevpanel = $('.sidewrapper:visible').prev().attr('id');

the .is() returns bool

Unlike the other filtering methods, .is() does not create a new jQuery object. Instead, it allows you to test the contents of a jQuery object without modification.

神魇的王 2024-11-09 19:43:04
if($("#sidepanel1").css("visibility") == "visible")
{
 // do stuff
}
if($("#sidepanel1").css("visibility") == "visible")
{
 // do stuff
}
執念 2024-11-09 19:43:04

根据文档is()只会返回一个布尔值那种情况。它不会返回 jQuery 对象的另一个实例,因此您的链已损坏。

According to the docs, is() would only return a boolean value in that case. It doesn't return another instance of the jQuery object, so your chain is broken.

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