jQ实现导航栏悬停下拉效果
先看看效果图:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>Document</title>
<!-- <link rel="stylesheet" href="css/01.css"> -->
<style>
* {
margin: 0;
padding: 0;
}
.nav-box {
text-align: center;
}
.nav-box span {
display: inline-block;
line-height: 40px;
width: 130px;
position: relative;
background: red;
}
.nav-box ul {
list-style-type: none;
position: absolute;
top: 40px;
line-height: 40px;
width: 130px;
background: blue;
display: none;
}
</style>
</head>
<body>
<div>
<div class="nav-box">
<span>一级菜单
<ul>
<li>二级菜单</li>
<li>二级菜单</li>
<li>二级菜单</li>
<li>二级菜单</li>
<li>二级菜单</li>
</ul>
</span>
<span>一级菜单
<ul>
<li>二级菜单</li>
<li>二级菜单</li>
<li>二级菜单</li>
<li>二级菜单</li>
<li>二级菜单</li>
</ul>
</span>
<span>一级菜单
<ul>
<li>二级菜单</li>
<li>二级菜单</li>
<li>二级菜单</li>
<li>二级菜单</li>
<li>二级菜单</li>
</ul>
</span>
<span>一级菜单
<ul>
<li>二级菜单</li>
<li>二级菜单</li>
<li>二级菜单</li>
<li>二级菜单</li>
<li>二级菜单</li>
</ul>
</span>
</div>
</div>
<script src="https://cdn.bootcdn.net/ajax/libs/jquery/3.5.1/jquery.min.js"></script>
<script>
$('.nav-box span').hover(function () {
$(this).find('ul').show();
}, function () {
$(this).find('ul').hide();
})
</script>
</body>
</html>
非常简单,通俗易懂,优化的地方大家可以指出。