摘要: <!DOCTYPE html> <html> <head> <meta charset="utf-8">
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>下划线跟随导航</title>
<script type="text/javascript" src="jquery-3.3.1.min.js"></script>
<style type="text/css">
*{padding: 0px;margin: 0px;}
ul{list-style: none; z-index:20;position: relative;}
li{float: left;cursor: pointer;height: 40px;width: 100px;text-align: center;line-height: 40px;color: #fff;}
.menu{width: 500px;height: 40px; position:relative;margin: 50px auto;box-shadow: 0 4px 20px #000;background:#FF9800;border-radius: 5px;}
</style>
<script type="text/javascript">
$(function(){
$('li').hover(
function(){
$x=parseInt($(this).attr('name'))*100
$('.move').stop().animate({left:$x+'px'},300)
},
function(){
$('.move').stop().animate({left:'0px'},300)
}
)
})
</script>
</head>
<body>
<div>
<ul>
<li name="0">首页</li>
<li name="1">课程中心</li>
<li name="2">计划中心</li>
<li name="3">考生中心</li>
<li name="4">留言中心</li>
</ul>
<div style="z-index: 10; width: 100px;height: 2px;background: #fff;position: absolute;margin-top:38px;"></div>
</div>
</body>
</html>总结:
z-index的层级关系
自定义动画animate()的运用
批改老师:天蓬老师批改时间:2018-12-16 11:29:48
老师总结:下划线自动跟随,有很多种实现方法, 想想看, 不用jQuery, 如何实现呢?