这是当前代码:子菜单正在自动打开,希望它保持关闭状态,直到单击主菜单-
http://jsbin.com/odegik/50/edit
<!DOCTYPE html>
<html>
<head>
<script class="jsbin"src="http://ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js"> </script>
<meta charset=utf-8 />
<title>DEMO</title>
<!--[if IE]>
<script src="http://html5shiv.googlecode.com/svn/trunk/html5.js"></script>
<![endif]-->
<style>
</style>
</head>
<body>
这是代码:jquery正在踢我的屁股:)
<nav class="menu-desktop">
<ul class="main-menu">
<li data-ref="Top1"><a href="/index.php" >Main Link1</a></li>
</ul>
<ul class="Top1" >
<li><a href="#" >sub link</a></li>
<li><a href="#1">sub name2</a></li>
<li><a href="#2">sub name3</a></li>
<li><a href="$">sub name4</a></li>
</ul>
<ul class="main-menu">
<li data-ref="Top2"><a href="#" >Main Link2</a></li>
</ul>
<ul class="Top2" >
<li><a href="#" >2sub link</a></li>
<li><a href="#1">sub name22</a></li>
<li><a href="#2">sub name23</a></li>
<li><a href="$">sub name24</a></li>
</ul>
<ul class="main-menu">
<li data-ref="Top3"><a href="#" >Main Link3</a></li>
</ul>
<ul class="Top3" >
<li><a href="#" >3sub link</a></li>
<li><a href="/_3Testingonly.php">sub name32</a></li>
<li><a href="#2">sub name33</a></li>
<li><a href="$">sub name34</a></li>
</ul>
</nav>
</body>
</html>
jquery 踢我的屁股 :)
var submenu;
$('.main-menu li').click(function(){
var elems = $('.menu-desktop ul:not(.main-menu)').length;
var $refClass = $('.' + $(this).attr('data-ref'));
var visible = $refClass.is(':visible');
$('.menu-desktop ul:not(.main-menu)').slideUp(100, function() {
if (elems == 1) {
if (!visible) $refClass.slideDown('fast');
}
elems--;
});
if (visible) $('#breadcrumbs-pc').animate({'margin-top':'0rem'}, 100);
else $('#breadcrumbs-pc').animate({'margin-top':'5rem'}, 100);
});