<button id="gotoTop" class="gotoTop" type="button">To the top</button>
window.onload = function () {
document.getElementById('gotoTop').onclick = function () {
scrollTo(document.body, 0, 100);
}
}
function scrollTo(element, to, duration) {
if (duration < 0) return;
var difference = to - element.scrollTop;
var perTick = difference / duration * 10;
setTimeout(function () {
element.scrollTop = element.scrollTop + perTick;
scrollTo(element, to, duration - 10);
}, 10);
}
.gotoTop {
position:fixed;
right:20px;
bottom:20px;
}
Du_A http://zhidao.baidu.com/question/1667937056094404787.html?push=keyword