abstract:<!DOCTYPE html><html lang="en"><head><meta charset="UTF-8"><meta name="viewport" content="width=device-width, initial-scale=1.0">&
<!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>jQuery实例-三级菜单</title>
<script src="jquery-3.3.1.js"></script>
<style>
* {
margin: 0px;
padding: 0px;
}
.menu {
width: 800px;
height: 32px;
margin: 20px auto;
background: lightcyan;
margin-top: 20px;
color: #7f69d1;
border: 1px solid #ccc;
border-radius: 5px;
position: relative;
}
ul {
list-style: none;
z-index: 20;
position: relative;
font-size: 15px;
}
li {
width: 100px;
height: 30px;
line-height: 30px;
text-align: center;
float: left;
color: lightblue;
cursor: pointer;
}
</style>
<script>
$(function(){
//导航鼠标跟随效果
$('li').hover(
function(){
$x=parseInt($(this).attr('name'))*100;
$('.block').stop().animate({left:$x+'px'},500);
},
function(){
$('.block').stop().animate({left:'0px'},500);
}
)
})
</script>
</head>
<body>
<div class="menu">
<ul>
<li name="0">首页</li>
<li name="1">产品示例</li>
<li name="2">公司新闻</li>
<li name="3">服务支持</li>
<li name="4">联系我们</li>
</ul>
<div class="block" style="z-index:10; width:100px; height:2px; background:rgb(118, 7, 223); position:absolute; top:30px;"></div>
</div>
</body>
</html>
Correcting teacher:灭绝师太Correction time:2019-03-18 16:53:04
Teacher's summary:练习的比较快,是想快速到后期内容吧,还是要稳稳的来哦!