摘要:<!DOCTYPE html><html><head> <meta charset="UTF-8"> <title>导航栏下滑线跟随</title> <script src="https://cdn.bootcss
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>导航栏下滑线跟随</title>
<script src="https://cdn.bootcss.com/jquery/3.3.1/jquery.js"></script>
<style>
*{padding: 0;margin: 0;}
ul{list-style: none;z-index: 20;position: relative;}
li{float: left;cursor: pointer;width: 100px;height: 30px;text-align: center;line-height: 30px;color: #fff}
.menu{width: 500px;position: relative;margin: 50px 0px 0px 20px;height: 32px;box-shadow: 0 2px 20px #000;background: #af3434;border-radius:3px;}
</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">666</li>
<li name="1">667</li>
<li name="2">668</li>
</ul>
<div class="block" style="z-index:10;width:100px;height:2px;background:#fff;position:absolute;top:30px;">
</div>
</div>
</body>
</html>
批改老师:天蓬老师批改时间:2019-01-11 22:41:34
老师总结:margin: 50px 0px 0px 20px; 以后凡是0之后, 不要添加单位了,例如 px