摘要:<!DOCTYPE html> <html> <head> <meta charset="UTF-8">
<!DOCTYPE html>
<html>
<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>重新布局下划线跟随导航</title>
<script src="https://code.jquery.com/jquery-3.1.1.min.js"></script>
<style>
* {
margin: 0;
padding: 0;
}
.nav {
width: 1200px;
height: 42px;
background: #029cff;
margin: 20px auto;
position: relative;
box-shadow: 0 2px 20px #000;
border-radius: 4px;
}
/* ul {
border-radius: 10px;
} */
ul li {
float: left;
list-style: none;
width: 120px;
line-height: 40px;
color: #fff;
text-align: center;
}
.line {
width: 120px;
height: 4px;
background: #fff;
z-index: 999;
position: absolute;
top: 38px;
}
</style>
</head>
<body>
<script>
$(document).ready(function() {
$('li').hover(
function() {
$num = parseInt($(this).attr('name')) * 120;
$('.line').stop().animate({
left: $num + 'px'
}, 300);
},
function() {
$('.line').stop().animate({
left: '0px'
}, 300);
}
)
})
</script>
<div>
<ul>
<li name="0">网站首页</li>
<li name="1">公司简介</li>
<li name="2">新闻中心</li>
<li name="3">产品介绍</li>
<li name="4">工程案例</li>
<li name="5">售后服务</li>
<li name="6">在线咨询</li>
<li name="7">人才招聘</li>
<li name="8">相关知识</li>
<li name="9">联系我们</li>
</ul>
<div></div>
</div>
</body>
</html>
批改老师:灭绝师太批改时间:2019-02-28 09:36:43
老师总结:必要的地方可以附上备注哦!整体完成的不错!