2012-04-17 54 views
0

我做这个教程:使第一导航项目开始在折叠式菜单关闭

http://michaeljacobdavis.com/tutorials/statesavingaccordion.html 这里是演示页: http://michaeljacobdavis.com/tutorials/statesavingaccordion/statesavingaccordion.html#1

我迷上它就好了,但我不希望第一次菜单项打开(关于)当用户第一次访问该网站。我希望关闭所有主菜单项,以便用户在点击其中的某个菜单项之前不能看到子菜单项。我试过,但无法弄清楚如何做到这一点 - 请帮助。以下是代码 - 关于部分始终在网站首次打开时打开 - 我希望它关闭。

<script type="text/javascript"> 
jQuery().ready(function(){ 
$('#navbar').accordion({ 
    autoHeight: false, 
    navigation: true, 
    header: '.navbaritem' 
}); 

$(".navbaritem").click(function(event){ 
     window.location.hash=this.hash; 
});  
}); 
</script> 

    <div id="navbar"> 
<div id="logo"> <a href="index.html"><img src="images/logo.png" width="234" height="191" border="0" /></a></div>  
<div class="navitemback"> 
<a class="navbaritem" href="#about" title="First Menu Item" name="about">about</a> 
<div> 
    <p><a href="#why">why we do it</a></p> 
    <p><a href="#press">press/awards</a></p> 
    <p><a href="#bio">bio</a></p> 
</div> 
</div> 

<div class="navitemback"> 
<a class="navbaritem" href="#commercial" title="Second Menu Item" name="commercial">commercial</a> 
<div> 
    <p><a href="#olivers">olivers</a></p> 
    <p><a href="#lemonade">lemonade</a></p> 
    <p><a href="#court">court</a></p> 
    <p><a href="#macks">macks</a></p> 
</div> 
</div> 

<div class="navitemback"> 
<a class="navbaritem" href="#residential" title="Third Menu Item" name="residential">residential</a> 
    <div> 
    <p><a href="#city">city</a></p> 
    <p><a href="#states">states</a></p> 
    <p><a href="#country">country</a></p> 
</div> 
</div> 
+0

请发表您的代码。 – 2012-04-17 08:41:29

+0

对不起,我现在在 – user1269988 2012-04-17 09:14:28

回答

2

这应该工作:

$('#navbar').accordion({ 
    autoHeight: false, 
    navigation: true, 
    header: '.navbaritem', 
    active: false, 
    collapsible: true 
}); 
+0

以上添加了,效果很好,非常感谢! – user1269988 2012-04-17 11:24:07

1

你好演示 :) http://jsfiddle.net/aCeyn/

,你也可以做到这一点没有collapsible这样的:

希望这有助于!有一个很好的,欢呼!

如果进一步想读其他属性或代码在这里看到:http://michaeljacobdavis.com/tutorials/statesavingaccordion/jquery-ui.min.js

哦,你也可以随意摆弄的的jsfiddle,把造型上为您的使用!

jQuery代码

$(document).ready(function(){ 
    $('#testMenu').accordion({ 
     autoHeight: false, 
     navigation: true, 
     header: '.testMenuItem', 
     active: false 
    }); 

    $(".testMenuItem").click(function(event){ 
      window.location.hash=this.hash; 

    });  


});​ 
+0

感谢您的帮助! – user1269988 2012-04-17 11:29:16

+0

@ user1269988不用担心男人一切都好,请不要忘记接受答案,提醒你,因为你似乎是新的,谢谢! – 2012-04-17 11:30:13

相关问题