让jquery垂直下滑菜单保持打开状态
一个菜鸟问题。答案可能非常简单,但不知何故,我无法弄清楚,并且需要继续我的项目。
我有一个垂直导航菜单,并且悬停时可以向下滑动。 但我希望菜单在滑落后保持打开状态。 我尝试删除最后一行代码,但这看起来不太漂亮。
我尝试实现 Stu Nicholls 方法 ,但没有得到它去工作。但这就是我想要的效果。
我的 HTML 菜单是:
<nav id="verticalmenu">
<ul>
<li><a class="slide" href="#">Kalendarium</a>
<ul class="down">
<li><a href="#">Konzerte</a></li>
<li><a href="#">Seminare</a></li>
<li><a href="#">Vortraege</a></li>
</ul>
</li>
<li><a href="#">Projekte</a>
</ul>
和它的 jquery:
<script type="text/javascript">
(function($){
//cache nav
var nav = $("#verticalmenu");
//add hovers to submenu parents
nav.find("li").each(function() {
if ($(this).find("ul").length > 0) {
//show subnav on hover
$(this).mouseenter(function() {
$(this).find("ul").stop(true, true).slideDown();
});
//hide submenus on exit
$(this).mouseleave(function() {
$(this).find("ul").stop(true, true).slideUp();
});
}
});
})(jQuery);
多谢!
A noob question. The answer is probably very simple, but somehow, i cannot figure it out, and need to move on in my project.
I have a vertical nav menu, and i have a slide down on hover.
But I would like the menu to stay open, once it has slid down.
I have tried deleting the last row of code, but that doe not look pretty.
I have tried to implement the Stu Nicholls method , but did not get it to work. But that is the effect i would like to have.
My HTML menu is :
<nav id="verticalmenu">
<ul>
<li><a class="slide" href="#">Kalendarium</a>
<ul class="down">
<li><a href="#">Konzerte</a></li>
<li><a href="#">Seminare</a></li>
<li><a href="#">Vortraege</a></li>
</ul>
</li>
<li><a href="#">Projekte</a>
</ul>
And the jquery to it:
<script type="text/javascript">
(function($){
//cache nav
var nav = $("#verticalmenu");
//add hovers to submenu parents
nav.find("li").each(function() {
if ($(this).find("ul").length > 0) {
//show subnav on hover
$(this).mouseenter(function() {
$(this).find("ul").stop(true, true).slideDown();
});
//hide submenus on exit
$(this).mouseleave(function() {
$(this).find("ul").stop(true, true).slideUp();
});
}
});
})(jQuery);
Thanks a lot!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
只需在文档加载时隐藏它们即可。不需要 if 检查,jquery 在内部进行此
操作: http://jsfiddle.net/Redwb/3/
just hide them on document load. there is no need of if check, jquery does that internally
fiddle : http://jsfiddle.net/Redwb/3/