您的位置:首页 > 其它

平滑地回到顶部

2016-11-04 13:37 246 查看
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);
});
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  回到顶部