87,965
社区成员
发帖
与我相关
我的任务
分享
<!DOCTYPE html>
<html>
<head lang="en">
<meta charset="UTF-8">
<title></title>
<style>
*{margin:0; padding:0; list-style-type:none;}
nav{height:40px; width:1000px; margin:auto; background:#ccc; position:relative; top:0; left:0;}
#A li{width:40px; height:40px; float:left; padding-left:20px;}
#B li{width:60px; height:40px; position:absolute; top:40px; left:0; background:green; display:none;}
</style>
</head>
<body>
<nav onmouseout="xi()">
<ul id="A">
<li onmouseover="show(0)">首页1</li>
<li onmouseover="show(1)">男装2</li>
<li onmouseover="show(2)">女装3</li>
<li onmouseover="show(3)">热卖4</li>
</ul>
<ul id="B" onmouseout="show2()" onmouseover="show3()">
<li>商品1</li>
<li>商品2</li>
<li>商品3</li>
<li>商品4</li>
</ul>
</nav>
</body>
<script>
var a=document.getElementById('A').getElementsByTagName('li');
var b=document.getElementById('B').getElementsByTagName('li');
function show(m){
b[m].style.display='block';
b[m].style.left=a[m].offsetLeft+'px';
}
function xi(){
for(var i=0;i< b.length;i++){
b[i].style.display='none';
}
}
window.setTimeout('xi()',1000);
function show2(){
for(var i=0;i< b.length;i++){
b[i].style.display='none';
}
}
</script>
</html>
someElement.onmouseout = function () {
// ch在函数顶端已经var过了
ch = setTimeout("something", 100);
};
(if (ch) {
clearTimeout(ch);
}
<!DOCTYPE html>
<html>
<head lang="en">
<meta charset="UTF-8">
<title></title>
<style>
*{margin:0; padding:0; list-style-type:none;}
.nav{height:28px;margin:0 auto;width:200px;}
.nav li.menu-s{position:relative; line-height:28px;float:left;padding-right:10px;}
.sub{ position:absolute; display:none; top:28px; background:#000;color:#fff; width:50px;}
a{ text-decoration:none;}
</style>
</head>
<body>
<ul class="nav" id="nav">
<li class="menu-s">
<a href="#">首页</a>
<ul class="sub">
<li>首页1</li>
</ul>
</li>
<li class="menu-s">
<a href="#">男装</a>
<ul class="sub">
<li>男装1</li>
<li>男装2</li>
</ul>
</li>
<li class="menu-s">
<a href="#">首页</a>
<ul class="sub">
<li>首页1</li>
</ul>
</li>
</ul>
</body>
<script>
var ulNav=document.getElementById('nav');
var aLi=ulNav.children;
for(var i=0;i<aLi.length;i++)
{
aLi[i].onmouseover=function(){
var subUl=this.getElementsByTagName('ul')[0];
subUl.style.display='block';
}
aLi[i].onmouseout=function(){
var subUl=this.getElementsByTagName('ul')[0];
subUl.style.display='none';
}
}
</script>
</html>