天天看點

jquery品優購電梯導航2-72

jquery品優購電梯導航2-72
<!DOCTYPE html>
<html lang="en">
 
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <script src="./js/jquery.min.js"></script>
    <style>
        .recommend {
            height: 1000px;
            background-color: red;
        }
        
        .fixedtool {
            width: 100px;
            height: 101px;
            background-color: pink;
        }
        
        .jiadian {
            width: 300px;
            height: 200px;
            background-color: salmon;
        }
        
        .shouji {
            width: 300px;
            height: 200px;
            background-color: salmon;
        }
    </style>
</head>
 
<body>
    <div class="recommend">1</div>
    <div class="fixedtool">
        <ul>
            <li class="current">家電</li>
            <li>手機</li>
        </ul>
    </div>
    <div class="floor ">
        <div class="jiadian w">家電</div>
        <div class="shouji w">手機</div>
    </div>
    <div class="jiadian">
 
    </div>
    <script>
        $(function() {
            var toolTop = $(".recommend").offset().top;
            $(window).scroll(function() {
                if ($(document).scrollTop() >= toolTop) {
                    $(".fixedtool").fadeIn();
                } else {
                    $(".fixedtool").fadeOut();
                }
            });
            //點選導航欄得到相應内容
            $(".fixedtool li").click(function() {
                //每次點選li去往頁面要去的位置
                //選出索引号的值去除他的位置
                console.log($(this).index());
                var current = $(".floor .w").eq($(this).index()).offset().top;
                //頁面滾動效果
                $("body,html").stop().animate({
                    scrollTop: current
                })
            })
        })
    </script>
</body>
 
</html>      

運作結果