js Top Small Demo


    <style>
        .divH {
            height: 1800px;
        }
        .divT {
            width: 50px;
            height: 50px;
            font-size: 18px;
            background-color: #2F4F4F;
            text-align: center;
            color: white;
            position: fixed;
            right: 18px;
            bottom: 18px;
        }
        .divT:hover{
            cursor: pointer;
        }
        .hide {
            display: none;
        }
    </style>
</head>
<body>
<div class="divH"></div>
<div class="divT hide" onclick="ReturnTop();"><strong>返回顶部</strong></div>

<script src="./jq/jquery-1.9.1.min.js"></script>
<script>
    window.onscroll = function () {
        var current = $(window).scrollTop();
        if (current > 180){
            $(".divT").removeClass("hide");
        }else {
            $(".divT").addClass("hide");
        }
    };

    function ReturnTop() {
        $(window).scrollTop(0);
    }
</script>

Top bottom right corner of the page there is a button, imitation Taobao? window.scrollTop () method

Guess you like

Origin www.cnblogs.com/renqiaoqiao/p/11568464.html