首页 / 话题 / 前端 / 文章详情

会站网返回顶部js+css代码实例

一直在的 2022-06-24 | 阅读(843) | 评论(0
<style>
    .back2top {
        position: fixed;
        right: 2rem;
        bottom: 2rem;
        z-index: 99;
        cursor: pointer;
        display: none;
    }
</style>
<div class="back2top">
    <button type="button" class="btn btn-light d-none d-lg-block">▲</button>
</div>
<script type="text/javascript">
    $(".back2top").click(function () {
        var speed = 500;//滑动的速度
        $('body,html').animate({ scrollTop: 0 }, speed);
        return false;
    });
    $(window).scroll(function () {
        height = $(document).scrollTop();
        if (height > 500) {
            $(".back2top").show()
        } else {
            $(".back2top").hide()
        };
    });
</script>
相关阅读
评论(0)
请登录
请登录后发表评论