2020-04-05 08:32:44 +08:00
|
|
|
scrollToTopDom.addEventListener('click', () => {
|
2020-04-03 23:52:46 +08:00
|
|
|
let scrollTopTimer = setInterval(function () {
|
|
|
|
let top = document.body.scrollTop || document.documentElement.scrollTop;
|
2020-04-07 11:57:53 +08:00
|
|
|
let speed = top / 3;
|
2020-04-03 23:52:46 +08:00
|
|
|
if (document.body.scrollTop !== 0) {
|
|
|
|
document.body.scrollTop -= speed;
|
|
|
|
} else {
|
|
|
|
document.documentElement.scrollTop -= speed;
|
|
|
|
}
|
|
|
|
if (top === 0) {
|
|
|
|
clearInterval(scrollTopTimer);
|
|
|
|
}
|
|
|
|
}, 30);
|
2020-04-07 11:57:53 +08:00
|
|
|
});
|