我做了一个下拉导航使用JQuery和CSS。当你点击一个特定的按钮时,它会打开,但是当再次点击该按钮时我无法关闭它。下面是我使用的(我已经创建了一个“关闭”按钮关闭它,但要当你点击你没有开相同的按钮它得到闭合)打开下拉导航,但无法关闭它(jQuery)
Jquery的代码:
$("#shadow").css("height", $(document).height()).hide();
$(".menubutton").click(function() {
$(".thetopmenu").css("padding","0px");
$(".thetopmenu").css("display","block"); // Displayes the menu
$(this).addClass("active"); // Add "active" class to selected tab
$("#shadow").toggle();
});
$(".close").click(function() {
$(".thetopmenu").css("display","none");
$(".menubutton").removeClass("active");
$("#overlay").css("display","none"); // Removes "active" class to selected tab
$("#shadow").toggle();
});
CSS:
.menubutton {
margin: 0; padding: 6px 0 0 0;
background: url(images/menu.png) no-repeat left top;
width: 44px; height: 16px;
position: absolute;
right: 10px;
top: 20px;
text-align: center;
display: block;
text-transform: uppercase;
color: #c3c3c3;
text-shadow: 0px -1px 0px #4f4f4f;
font-family: MPSemibold, Arial;
font-size: 10px;
text-decoration: none;
}
.menubutton:link {
text-transform: uppercase;
color: #c3c3c3;
text-shadow: 0px -1px 0px #4f4f4f;
font-family: MPSemibold, Arial;
font-size: 10px;
text-decoration: none;
}
.menubutton:active, .menubutton.active, menubutton:hover {
background: url(images/menuh.png) no-repeat left top;
color: #fff;
}
.thetopmenu {
display: none;
position: absolute;
left: 0;
z-index: 999;
top: 61px;
width: 100%;
}
HTML:
<a href="#" class="menubutton"><span>Menu</span></a>
<div class="thetopmenu">
<ul id="content">
<li><a href="ladies.php">Ladies' Collection</a></li>
<li><a href="gents.php">Gents' Collection</a></li>
<li><a href="store.php">Store Locator</a></li>
<li><a href="#" class="close">Close</a></li>
</ul>
</div>
的#shadow刚刚淡出屏幕的休息和叶菜单正常。我认为这很简单,但我在jQuery中并不擅长。
谢谢
谢谢,那正是我正在寻找的。我尝试了 - 如果 - 但没有设法让它工作。你的作品就像一个魅力。再次感谢;) – pomaaa 2011-02-16 20:56:17
不客气。不要忘记标记答案是正确的。 :)另外,我会建议修改你的代码,以便你可以使用更通用的函数。就像我在我的mod中使用$(this)一样,如果多个菜单在等式中,您应该能够使代码具有通用性并且可重用。让我知道你是否需要这方面的帮助。 – clifgriffin 2011-02-16 21:01:25