宋柏霖的第十六个作业

Original 2019-04-20 11:05:22 225
abstract:<!DOCTYPE html><html><head>    <title>下滑线跟随导航</title>    <meta charset="utf-8"/>    <script type="text/javascript&qu

<!DOCTYPE html>
<html>
<head>
   <title>下滑线跟随导航</title>
   <meta charset="utf-8"/>
   <script type="text/javascript" src="jquery-3.4.0.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:500px;position:relative;margin:20px auto;height:32px;box-shadow: 0 2px 20px #000;background: blue;border-radius:3px }
       a{color:#F5F5F5;
         text-decoration: none;
       }
       a:hover{color: #5dafd1;}

   </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"><a href="http://www.baidu.com">百度</a></li>
       <li name="1"><a href="http://www.sina.com.cn">新浪</a></li>
       <li name="2"><a href="http://www.qq.com">腾讯</a></li>
       <li name="3"><a href="http://www.jd.com">京东</a></li>
       <li name="4"><a href="http://www.taobao.com">淘宝</a></li>
   </ul>
   <div class="block" style="z-index:10;width:100px;height:2px;background:#fff;position:absolute;top:30px;"></div>

</div>

</body>
</html>

Correcting teacher:西门大官人Correction time:2019-04-20 13:35:21
Teacher's summary:这里是用js来实现,还可以用css的hover伪类来实现。

Release Notes

Popular Entries