那是因为你离开的时候就马上调用了$(".u_ddl").hide()当然会马上消失了,开个定时器让他延时消失就可以了
$(document).ready(function(){
var timer=null//定义一个定时器变量
$(".u_menu_setting").mouseover(function(){
clearTimeout(timer)
$(".u_ddl").show()
})
$(".u_menu_setting").mouseout(function(){
timer=setTimeout(function(){
$(".u_ddl").hide()
},300)
})
$$(".u_ddl").mouseout(function(){
timer=setTimeout(function(){
$(".u_ddl").hide()
},300)
})
$(".u_ddl").mouseover(function(){
clearTimeout(timer)
$(".u_ddl").show()
})
})
jquery下拉菜单怎么做,一个简单的纯手写例子
你说的是类似级联菜单那种吗?如果IE8、火狐等其他浏览器正常,这个的原因可能有几个:
1、如果你用的onmouseout事件,建议你换成onmouseleave试试,因为存在事件冒泡的问题。
2、如果存在子菜单,在子菜单上面也bind一个onmouseenter和onmouseleave事件。
参考:
$("#div_Exa
ul
li
a").mouseover(function
()
{
$(this).parent().children("ul").slideDown(100)
$(this).parent().siblings().children("ul").hide(100)
}).mouseleave(function
()
{
var
selector_Sub_Menu
=
$(this).parent().children("ul")
selector_Sub_Menu.hide()
selector_Sub_Menu.bind("mouseover",
function
()
{
selector_Sub_Menu.show()
})
.bind("mouseleave",
function
()
{
selector_Sub_Menu.hide()
})
})希望可以帮到你。
请教jQuery高手,写下拉菜单,怎么控制二级菜单出现与消失
slideDown(),slideUp()
事件就用mouseenter mouseleave
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title></title>
<style type="text/css">
* {
margin: 0
padding: 0
}
ul {
list-style: none
}
.wrap {
width: 330px
height: 30px
margin: 100px auto 0
padding-left: 10px
background-image: url(imgs/bg.jpg)
}
.wrap li{
background-image: url(imgs/libg.jpg)
}
.wrap > ul > li {
float: left
margin-right: 10px
position: relative
}
.wrap a {
display: block
height: 30px
width: 100px
text-decoration: none
color: #000
line-height: 30px
text-align: center
}
.wrap li ul {
position: absolute
top: 30px
display: none
}
</style>
<script src="jq.js"></script>
<script type="text/javascript">
$(function(){
// 分析思路:将鼠标到任何一个li上面 让对应的li里面的ul 显示 让其他的 li里面的ul隐藏
// 1 给所有的.wrap>ul>li 添加注册鼠标移上事件 mouseover
$(".wrap>ul>li").mouseover(function(){
// 2 让它里面的直接子元素ul 去滑入
$(this).children("ul").stop().slideDown()
})
//2 给所有的.wrap>ul>li 添加注册鼠标移出事件 mouseout
$(".wrap>ul>li").mouseout(function(){
// 2 让它里面的直接子元素ul 去滑出
$(this).children("ul").stop().slideUp()
})
})
</script>
</head>
<body>
<div >
<ul>
<li>
<a href="javascript:" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" >一级菜单1</a>
<ul >
<li>
<a href="javascript:" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" >二级菜单11</a>
</li>
<li>
<a href="javascript:" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" >二级菜单12</a>
</li>
<li>
<a href="javascript:" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" >二级菜单13</a>
</li>
</ul>
</li>
<li>
<a href="javascript:" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" >一级菜单2</a>
<ul>
<li>
<a href="javascript:" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" >二级菜单21</a>
</li>
<li>
<a href="javascript:" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" >二级菜单22</a>
</li>
<li>
<a href="javascript:" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" >二级菜单23</a>
</li>
</ul>
</li>
<li>
<a href="javascript:" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" >一级菜单3</a>
<ul>
<li>
<a href="javascript:" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" >二级菜单31</a>
</li>
<li>
<a href="javascript:" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" >二级菜单32</a>
</li>
<li>
<a href="javascript:" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" >二级菜单33</a>
</li>
</ul>
</li>
</ul>
</div>
</body>
</html>
$(document).ready(function(){
init()
})
function
init(){
$("#Menu>ul>li").hover(
function(){
$(this).children("ul").fadeIn("fast")
},
function(){
$(this).children("ul").fadeOut("fast")
}
)
}
还需要强调的是,二级菜单的距离不要离一级导航有缝隙,否则会点不到二级菜单的。这个就是二级菜单的样式的问题了~
以上就是关于jquery下拉菜单求助全部的内容,如果了解更多相关内容,可以关注我们,你们的支持是我们更新的动力!