摘要:<!DOCTYPE html> <html> <head> <title>下滑线跟随导航</title> <meta charset="utf-8" /> <script type=&qu
<!DOCTYPE html> <html> <head> <title>下滑线跟随导航</title> <meta charset="utf-8" /> <script type="text/javascript" src="jquery-3.3.1.js"></script> <style type="text/css"> * { padding: 0; margin: 0; } ul { list-style: none; z-index: 20; position: relative; font-size: 15px; } li { float: left; cursor: pointer; width: 100px; height: 30px; text-align: center; line-height: 30px; color: #fff; font-weight: bold; } .menu { width: 600px; position: relative; margin: 20px auto; height: 32px; box-shadow: 0 2px 20px #000; background: blue; border-radius: 3px } </style> <script type="text/javascript"> $(function() { $('li').hover( function() { $x = parseInt($(this).attr('name')) * 100 $('.block').stop().animate({left:$x + 'px'}, 300) }, function() { $('.block').stop().animate({left:'0px'}, 300) } ) }) </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> <li name="5">人事处</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-24 08:57:01
老师总结:定位的属性值, 是字符串, 不是数值, 一定要注意, 它与偏移量是不同的