如何在 JQuery 中向上滑动(隐藏)子 div?
好吧,假设我有一个在嵌套 div 中构建的导航系统,当我将鼠标悬停在菜单 div 上并隐藏子菜单 div(和子菜单 div)时,我想显示子菜单 div(和子子菜单 div)。子菜单 div)在鼠标移出时,或者更准确地说,当我将鼠标悬停在不同的菜单 div 上时。
最好的方法是什么?
到目前为止,这就是我所得到的:
<script type="text/javascript">
$('.menu').mouseover(function(){
$(this).children(".submenu").each(function(i){
$(this).delay(1000).slideDown("slow");
$(this).mouseover(function(i){
$(this).children(".sub_submenu").each(function(i){
$(this).delay(1000).slideDown("slow");
});
});
</script>
<div id="" class="menu">
menu1
<div id="" class="submenu">
submenu11
<div id="" class="sous_sousmenu">
sub_submenu111
</div>
<div id="" class="sub_submenu">
sub_submenu112
</div>
</div>
<div id="" class="submenu">
submenu12
</div>
</div>
<div id="" class="menu">
<a href="#">menu2</a>
<div id="" class="submenu">
sousmenu21
</div>
<div id="" class="submenu">
submenu22
<div id="" class="sub_submenu">
sub_submenu21
</div>
</div>
</div>
现在,当我将鼠标悬停在正确的菜单 div 上时,一切正常(显示子菜单和子子菜单)。 现在,当我将鼠标悬停在不同的 .menu div 上时,我应该在哪里/何时/如何告诉脚本对所有 .submenu 和 .sub_submenu 进行向上滑动?
谢谢
Ok, let's say I have a navigation system constructed in nested divs and I want to show sub-menu divs (and sub-sub-menu divs) when I do a mouseover on the menu div AND hide sub-menu divs (and sub-sub-menu divs) on a mouseout, or more precisely, when I mouseover a different menu div.
What would be the best way?
So far, here's what I've got :
<script type="text/javascript">
$('.menu').mouseover(function(){
$(this).children(".submenu").each(function(i){
$(this).delay(1000).slideDown("slow");
$(this).mouseover(function(i){
$(this).children(".sub_submenu").each(function(i){
$(this).delay(1000).slideDown("slow");
});
});
</script>
<div id="" class="menu">
menu1
<div id="" class="submenu">
submenu11
<div id="" class="sous_sousmenu">
sub_submenu111
</div>
<div id="" class="sub_submenu">
sub_submenu112
</div>
</div>
<div id="" class="submenu">
submenu12
</div>
</div>
<div id="" class="menu">
<a href="#">menu2</a>
<div id="" class="submenu">
sousmenu21
</div>
<div id="" class="submenu">
submenu22
<div id="" class="sub_submenu">
sub_submenu21
</div>
</div>
</div>
Right now, everything is working (showing sub-menu and sub-sub-menus) when I mouseover the proper menu div.
Now, where/when/how should I tell the script to do a slideUp of all .submenu and .sub_submenu when I do a mouseover of a different .menu div?
Thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
尝试这样的事情(演示):
HTML
脚本
Try something like this (demo):
HTML
Script