简体   繁体   English

jQuery Accordion的简单问题

[英]Simple issue with jQuery Accordion

I have a simple jQuery accordion which works... almost perfectly :) 我有一个简单的jQuery手风琴,可以工作... 几乎完美:)

As you can see from the demo, I currently have the navigation "open" as I'm in the "Team" page. 正如您在演示中看到的那样,我现在在“团队”页面中将导航设置为“打开”。

Is it possible when I click 'About Us', it closes the element altogether. 当我点击“关于我们”时,它可以完全关闭元素。 As you can see from the demo it closes it, but then quickly re-opens it. 正如您从演示中看到的那样,它会将其关闭, 随后会快速重新打开它。 I guess this occurs because of the code on line 27 of my CSS. 我想这是因为我的CSS 第27行的代码。

Here is my demo : http://jsfiddle.net/URYzK/5/ 这是我的演示http//jsfiddle.net/URYzK/5/

Here is my JavaScript: 这是我的JavaScript:

jQuery(function($) {

    $('#accordion > li > a').click(function (e) {
        if ($(this).next('ul').length == 0) {
            // link is for navigation, do not set up accordion here
            return;
        }

        // link is for accordion pane

        //remove all the "Over" class, so that the arrow reset to default
        $('#accordion > li > a').not(this).each(function () {
            if ($(this).attr('rel')!='') {
                $(this).removeClass($(this).attr('rel') + 'Over');
            }

            $(this).siblings('ul').slideUp("slow");
        });

        //showhide the selected submenu
        $(this).siblings('ul').slideToggle("slow");

        //addremove Over class, so that the arrow pointing downup
        $(this).toggleClass($(this).attr('rel') + 'Over');
        e.preventDefault();
    });

});

Many thanks for any help here. 非常感谢您的帮助。

Remove display:none from #accordian ul and remove the .children CSS entirely. 删除display:none#accordian ul和删除.children完全CSS。 I believe this creates the behavior you want. 我相信这会创造出你想要的行为。 You were setting the children ul to be display:none , and then trying to force .children , which is a ul , to be display:block later, which is why they were fighting. 你正在设置孩子ul display:none ,然后试图强制.children ,这是一个uldisplay:block稍后display:block ,这就是为什么他们在战斗。

Updated your jsFiddle as well. 更新了你的jsFiddle。

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

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