二级导航--鼠标悬浮菜单出现二级菜单

二级导航–鼠标悬浮菜单出现二级菜单

<!DOCTYPE html>

<html>
<head >
<meta charset="utf-8">
<title>鼠标悬浮菜单出现二级菜单</title >
<style>
    a{
    color: #fff;
    text-decoration: none;
    }
    ul {
    margin: 0;
    list-style: none;
    }
    #menu {
    width: 500px;
    height: 60px;
    background: slategray;
    border-radius: 6px;
    box-shadow: 2px 2px 5px snow;
    }
    #menu li {
    float: left;
    margin-top: 10px;
    line-height: 22px;
    padding: 0;
    position: relative;
    }
    #menu li a {
    padding: 10px 20px;
    display: inline-block;
    }
    #menu li .hover {
    background: #fff;
    opacity: 0.5;
    color: gray;
    border-radius: 5px;
    }
    #menu li .lis {
    width: 300px;
    height: 40px;
    line-height: 40px;
    border-radius: 5px;
    background: lightblue;
    position: absolute;
    top: 70px;
    }
    #menu li .lis a {
    padding: 0 10px;
    background: none;
    opacity: 1;
    color: #fff;
    }
    #menu li .lis a:hover {
    text-decoration: underline;
    }
</style>
<script>
    window.onload = function() {
    var oUl = document.getElementById('menu');
    var aLi = oUl.getElementsByTagName('li');
    var aDiv = oUl.getElementsByTagName('div');
    var timer = null;
    for (var i = 0; i < aLi.length; i++) {
    var oA = aLi[i].getElementsByTagName('a')[0];
    oA.index = i;
    clearTimeout(timer);
    oA.onmouseover = function() {
    this.className = 'hover';
    aDiv[this.index].style.display = 'block';
}
oA.onmouseout = function() {
    this.className = '';
    n = this.index;
    timer = setTimeout(function() {
    aDiv[n].style.display = 'none';
}, 200);
}
aDiv[i].onmouseover = function() {
    clearTimeout(timer);
    this.style.display = 'block';
}
aDiv[i].onmouseout = function() {
    this.style.display = 'none';
}
}
}
</script>
</head>
<body>
<div>
<ul id = "menu">
<li>
<a href ="javascript:;" >首页</a>
<div class ="lis" style ="display:none;">
<a href = "javascript:;">手机</a >
<a href = "javascript:;">电脑</a>
<a href="javascript:;">知识点</a>
</div>
</li>
<li>
<a href="javascript:;">品牌</a>
<div class="lis" style="display:none;">
<a href="javascript:;">华为</a>
<a href="javascript:;">小米</a>
<a href="javascript:;">苹果</a>
</div>
</li>
<li>
<a href="javascript:;">课程</a>
<div class="lis" style="display:none;">
<a href="javascript:;">js课</a>
<a href="javascript:;">css3课</a>
<a href="javascript:;">HTML5课</a>
<a href="javascript:;">Jquery课</a>
</div>
</li>
</ul>
</div>
</body>
</html>
  • 效果如下

这里写图片描述

  • 4
    点赞
  • 17
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值