1.当页面滚动到一定位置时显示回到顶部的按钮
$(window).scroll(function () {
var scrollt = document.documentElement.scrollTop + document.body.scrollTop;
if ( scrollt > 200 ){
$(".to-top").fadeIn(500);
} else {
$(".to-top").fadeOut(500);
}
});
2.点击回到顶部,平滑的回到顶部
$(".to-top").click(function(){
$("html,body").animate({scrollTop: 0}, 400);
});