置顶按钮

Add HTML

<main class="placeholder">
</main>
<div id="topping">
    顶
</div>

Add CSS

        body {
            margin: 0;
        }

        .placeholder {
            width: 100%;
            height: 4000px;
            background-image: url("images/your_name.jpg");
        }

        #topping {
            display: inline-block;
            width: 20px;
            height: 20px;
            font-size: 18px;
            color: #111;
            border: 1px solid #111;
            position: fixed;
            bottom: 20px;
            right: 20px;
        }

Add jQuery

    $("#topping").click(function () {
        $('body,html').animate({scrollTop: 0}, 1000); //1000代表1秒时间回到顶点
    })

猜你喜欢

转载自blog.csdn.net/qq_39314291/article/details/82155908
今日推荐