下划线跟随导航作业

原创 2019-02-26 12:16:54 404
摘要:<!DOCTYPE html><html><head>    <meta charset="utf-8"> <title>jQuery的动画效果--下划线跟随导航</title> <script type="text/javascript" src="

<!DOCTYPE html>

<html>

<head>

    <meta charset="utf-8">

<title>jQuery的动画效果--下划线跟随导航</title>

<script type="text/javascript" src="jquery-3.3.1.min.js"></script>

  <style type="text/css">

  *{margin:0px;padding:0px;}

   .nav{width:655px;height:48px;background:#272822;position:relative; margin:0px auto;border-radius: 10px;margin-top:40px;box-shadow: 0px 2px 20px #272822;}

    ul{list-style:none;position: relative;z-index: 20px;}

    li{float:left;line-height: 48px;width:130px;font-size:16px;font-weight:bold;color:#fff;border-right: 1px solid #fff;text-align:center;cursor: pointer;}

    li:nth-child(5){border-right:none;}

    .xhx{width:130px;height:3px;background:#29B452;z-index: 10px;position: absolute;top:45px;}

  </style>

  <script type="text/javascript">

   $(function(){

    $('li').hover(function(){

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

    $('.xhx').stop().animate({left:$x+'px'},300)

    },

        function(){

        $('.xhx').stop().animate({left:'0px'},300)

        }

    )

   })

  </script>


</head>

<body>

<div class="nav">

   <ul>

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

      <li name="1">企业简介</li>

      <li name="2">新闻中心</li>

      <li name="3">产品中心</li>

      <li name="4">联系我们</li>

   </ul>

   <div class="xhx"></div>

</div>

</body>

</html>


批改老师:韦小宝批改时间:2019-02-26 13:03:01
老师总结:写的很不错 这种效果看上去就可以让导航高大上一点

发布手记

热门词条