<div id="btn3" class="bt">回到顶部</div>
//总距离,总时间,过渡时间
$('#btn3').click(function () {
var $page = $('html,body')
var distance = $('html').scrollTop() + $('body').scrollTop()
var totaltime = 500
var time = 50
var itemdistance = distance / (totaltime / time)
var intervalId = setInterval(function () {
distance -= itemdistance
if (distance<=0){
distance=0
clearInterval(intervalId)
}
$page.scrollTop(distance)
},time)
})
网友评论