返回顶部

 //html
 <div class="to-top" data-id="#index"></div>
    
 //使用 返回顶部
    $(".to-top").unbind("click").click(function(){
        var ele=$(this);
        reachToPoint(ele);
    });  
    function reachToPoint(ele){
        var id=ele.attr("data-id");
        if($(id).length != 0){
            var top=$(id).offset().top - 70 + 'px';
            $('html').animate({scrollTop:top},500);
            $('body').animate({scrollTop:top},500);
        }
    };
原文地址:https://www.cnblogs.com/muzs/p/8532079.html