JQuery使用其自定义动画制作跟随导航效果

Original 2018-12-02 23:10:07 189
abstract:<!DOCTYPE html><html> <head>  <title>下滑线跟随导航</title>  <meta charset="utf-8"/>  <script type="text/javascript" src="j

<!DOCTYPE html>

<html>

 <head>

  <title>下滑线跟随导航</title>

  <meta charset="utf-8"/>

  <script type="text/javascript" src="jquery-3.3.1.min.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: #AF3434;border-radius:3px }

  </style>

         <script type="text/javascript">

                $(function(){

                $('li').hover(

                function(){

                $x=parseInt($(this).attr('name'))*100

                $('.block').stop().animate({left:$x+'px'},100)

                },

                function(){

                $('.block').stop().animate({left:'0px'},500)

                }

                )

                })



         </script>

    </head>

    <body>

         <div class="menu">

              <ul>

                 <li name="0">首页</li>

                 <li name="1">php学习</li>

                 <li name="2">李昊锦老大</li>

                 <li name="3">李昊锦大哥</li>

                 <li name="4">李昊锦大人</li>

              </ul>

                 

                <div class="block" style="z-index:10;width:100px;height:2px;background:#fff;position:absolute;top:30px"></div>

               </div>

            </div>

    </body>

</html>


Correcting teacher:灭绝师太Correction time:2018-12-03 09:36:56
Teacher's summary:js控制,只要条理清楚就很简单,完成的不错!

Release Notes

Popular Entries