zoukankan      html  css  js  c++  java
  • jQuery实现动画滑动二级菜单

    <!DOCTYPE html>
    <html lang="en">
    <head>
        <meta charset="UTF-8">
        <title>Title</title>
        <script src="jquery-3.2.1.js" type="text/javascript"></script>
        <script src="滑动动画.js" type="text/javascript"></script>
        <link rel="stylesheet" href="滑动动画.css" type="text/css"/>
    </head>
    <body>
    <div class="header">
        <ul>
            <li class="nav"><a href="#">one</a></li>
            <li class="nav"><a href="#">two</a></li>
            <li class="nav"><a href="#">three</a></li>
            <li class="nav"><a href="#">four</a></li>
        </ul>
    </div>
    <div class="big">
        <div class="main">
            <div class="a"></div>
            <div class="b"></div>
            <div class="c"></div>
            <div class="d"></div>
        </div>
    </div>
    </body>
    </html>
    *{
        margin:0;
        padding:0;
    }
    .header{
        background-color:aqua;
        height: 40px;
    
    }
    ul{
        list-style: none;
    }
    ul li{
        float: left;
        text-align: center;
        line-height: 40px;
        border-right: 1px solid white;
    }
    a{
        text-decoration:none;
        color: white;
        display: block;
        padding: 0 20px;
    }
    ul li a:hover {
        background-color: white;
        color: aqua;
    }
    .big{
        width:100%;
        overflow: hidden;
        height:0;
        top:40px;
    }
    .main{
        width: 400%;
        height:500px;
    }
    .a{
        width:25%;
        height: 500px;
        background-color: yellow;
        float:left;
    }
    .b{
        width:25%;
        height: 500px;
        background-color: red ;
        float:left;
    }
    .c{
        width:25%;
        height: 500px;
        background-color: black ;
        float:left;
    }
    .d{
        width:25%;
        height: 500px;
        background-color: blue;
        float:left;
    }
    $(function () {
        $(".header").on("click","li",function () {
            var curIndex = $(this).index(), mlValue = "-" + curIndex * 100 + "%";
            /*index()获取header里的li,并确定为第几个然后返回数字*/
            if ($(".big").hasClass("active")) {
                $(".main").animate({marginLeft: mlValue});
            }
            else{
                $(".main").css({marginLeft:mlValue});
                $(".big").animate({height:"500px"}).addClass("active");
            }
        });
    });
  • 相关阅读:
    Python学习(十六)内置函数,递归
    Python学习(十五)json串使用,不固定参数,关键词参数
    Python学习(十四)常量,局部变量,全局变量
    python学习(十三)函数
    python学习(十二)模块
    Python学习(十一)文件指针,文件操作练习,修改文件
    mongodb聚合
    mongodb
    软件测试需要学习哪些课程
    Jmeter的使用和监控分析
  • 原文地址:https://www.cnblogs.com/yzhweb/p/7368029.html
Copyright © 2011-2022 走看看