SOURCE

console 命令行工具 X clear

                    
>
console
$(function () {
  // 绑定 hover 事件
  $(".nav li").hover(
    function () {
      // stop 方法用于停止当前正在运行的动画
      $("span", this).stop().css("height", "10px");

      // 添加动画
      $("span", this).animate(
        {
          //使底部红线和菜单一样宽
          left: "0",
          width: "100%",
          right: "0",
        },
        200
      );
    },
    
    function () {
      $("span", this).stop().animate(
        {
          //鼠标移出时 重置小红线位置及长度
          left: "50%",
          width: "0",
        },
        200
      );
    }
  );
});
<!DOCTYPE html>
<html>
  <head>
    <meta charset="utf-8" />
    <title>jQuery 特效导航</title>
    <link rel="stylesheet" href="css/nav.css" />
  </head>
  <body>
    <!-- 页面头部 header -->
    <div class="header">
      <!-- 页面导航 nav -->
      <div class="nav">
        <!-- 菜单列表 -->
        <!-- span 标签用于添加特效 -->
        <ul>
          <li>
            <a href="https://www.lanqiao.cn/" target="_blank">首页</a
            ><span></span>
          </li>
          <li>
            <a href="https://www.lanqiao.cn/" target="_blank">栏目 1</a
            ><span></span>
          </li>
          <li>
            <a href="https://www.lanqiao.cn/" target="_blank">栏目 2</a
            ><span></span>
          </li>
          <li>
            <a href="https://www.lanqiao.cn/" target="_blank">栏目 3</a
            ><span></span>
          </li>
          <li>
            <a href="https://www.lanqiao.cn/" target="_blank">栏目 4</a
            ><span></span>
          </li>
        </ul>
      </div>
    </div>
    <script src="https://cdn.bootcss.com/jquery/3.3.1/jquery.min.js"></script>
    <script src="js/nav.js"></script>
  </body>
</html>
body,
div,
ul,
li,
a,
span{
    margin: 0;
    padding: 0;
}

ul{
    list-style: none;
}

.header{
    width: 100%;
    background: grey;

}
.nav{
    width: 1000px;
    margin:0 auto;
    overflow: hidden;

}
.nav ul li{
    height: 40px;
    line-height: 40px;
    float: left;
    padding: 10px 5px;
    margin: 0px 5px;
    position: relative;

}
.nav ul li a {
  color: #666;
  font-family: "Microsoft Yahei";
  font-size: 14px;
  text-decoration: none;
}
.nav ul li a:hover{
    background: #f66;
}
.nav ul li span{
    display: block;
    position: absolute;
    width: 0px;
    height: 0px;
    background: #f66;
    top: 58px;
    left: 50%;
}