• 爬楼


    
            <!DOCTYPE html>
    <html lang="en">
    <head>
        <meta charset="UTF-8">
        <title>Document</title>
        <style>
            *{
                margin: 0;
                padding: 0;
                list-style-type: none;
            }
            .div1{
                 90%;
                margin: 0 auto;
                height: 700px;
                background: red;
                color: #fff;
                line-height: 700px;
                font-size: 100px;
                text-align: center;
            }
            .div2{
                 90%;
                margin: 0 auto;
                height: 700px;
                background: pink;
                color: #fff;
                line-height: 700px;
                font-size: 100px;
                text-align: center;
            }
            .div3{
                 90%;
                margin: 0 auto;
                height: 700px;
                background: green;
                color: #fff;
                line-height: 700px;
                font-size: 100px;
                text-align: center;
            }
            .div4{
                 90%;
                margin: 0 auto;
                height: 700px;
                background: blue;
                color: #fff;
                line-height: 700px;
                font-size: 100px;
                text-align: center;
    
            }
    
            .nav{
                 80px;
                height: 204px;
                position: fixed;
                right: 20px;
                bottom: 40px;
            background: #b6b6b6;
    
            }
            .nav li{
                height: 50px;
                line-height: 50px;
                text-align: center;
                font-size: 20px;
                color: #fff;
                cursor: pointer;
                border-top: 1px solid #b6b6b6;
            }
        </style>
    </head>
    <body>
    <ul class="nav">
        <li>div1</li>
        <li>div2</li>
        <li>div3</li>
        <li>div4</li>
    </ul>
        <div class="div1">我是DIV1</div>
        <div class="div2">我是DIV2</div>
        <div class="div3">我是DIV3</div>
        <div class="div4">我是DIV4</div>
    </body>
    <script src="../jquery.2.2.4.js"></script>
    <script>
    
        $(".nav").children("li").click(function(){
            // 获取点击元素的索引
            // console.log($(this).index())
            // 根据索引,拿到对应的div
            // console.log($("div").eq($(this).index()))
            // 根据div获取自己的距离顶部的距离
            // console.log($("div").eq($(this).index()).offset().top)
    
            // 无动画版
            // 设置给document的scrollTop
            // $(document).scrollTop($("div").eq($(this).index()).offset().top)
            
            // 动画版
            $("html").animate({
                scrollTop:$("div").eq($(this).index()).offset().top
            })
        })
    
    </script>
    </html>
    
  • 相关阅读:
    rails 相关文件
    linux学习---vi进行多行的copy,cut
    设计
    互联网---现在正在变成过去
    testing
    TTl
    如何成为优秀的性能测试工程师
    linuX学习
    Programiz 中文系列教程·翻译完成
    Programiz C 语言教程·翻译完成
  • 原文地址:https://www.cnblogs.com/sansancn/p/10973269.html
Copyright © 2020-2023  润新知