点击按钮返回顶部

<!-- 10置顶 -->
    <div class="totop">
        <img src="images/totop.png" />
    </div>
    <script>
        $(function() {
            $(window).scroll(function() {
                var scroHei = $(window).scrollTop();//滚动的高度
                if (scroHei > 400) {
                    $('.totop').fadeIn();
                } else {
                    $('.totop').fadeOut();
                }
            })
            /*点击返回顶部*/
            $('.totop').click(function() {
                $('body,html').animate({
                    scrollTop: 0
                }, 600);
            })
        })
    </script>
 
 
参考链接:https://www.bbsmax.com/A/MAzAk1ey59/
posted @ 2022-02-19 10:37  宅女二二  阅读(33)  评论(0)    收藏  举报