HTML页面实现返回顶部效果 go to top

1、首先导入jQuery插件。

2、js代码:

$(window).scroll(function () {
     if($(window).scrollTop()>=100) {
           $(".backtop").fadeIn();
     }else {
                                    
           $(".backtop").fadeOut();
     }
});
                        
                    
$(".backtop").click(function(event){    
       $('html,body').animate({scrollTop:0}, 500);
       return false;
 });

3、css代码:

a.backtop {
                background: url("./sw/images/backtotop.png") no-repeat scroll center center rgba(0, 0, 0, 0);
                bottom: 20px;
                cursor: pointer;
                display: none;
                height: 70px;
                position: fixed;
                right: 20px;
                text-indent: -9999px;
                width: 70px;
                z-index: 100;
            }

4、页面代码:

<a class="backtop" >
                            <h6>返回顶部啊</h6>
                        </a>
原文地址:https://www.cnblogs.com/tq03/p/3985502.html