滑动一段距离后出现回到顶部点击渐渐滚动到顶部效果


        .go-top {
            position: fixed;
            bottom: 4rem;
            left: 1rem;
            display: none;
            margin-bottom: 1rem;
            user-select: none;
            cursor: pointer;
            opacity: .7;
            width: 5rem;
            height: 5rem;
            border-radius: 50%;
            box-shadow: 0 .5rem 1rem rgba(0, 0, 0, .15);
            text-align: center;
            line-height: 5rem;
        }

    

        $(window).bind("scroll", function () {
            let scrollTopNum = $(document).scrollTop();
            (scrollTopNum > 300) ? $('.go-top').fadeIn(500) : $('.go-top').fadeOut(500);
        });

        $('.go-top').on('click', function () {
            $("html, body").animate({scrollTop: 0}, 500);
        });

相关