2020-04-03 23:52:46 +08:00
|
|
|
const scrollToTop = document.querySelector('.scroll-to-top');
|
|
|
|
scrollToTop.addEventListener('click', () => {
|
|
|
|
let scrollTopTimer = setInterval(function () {
|
|
|
|
let top = document.body.scrollTop || document.documentElement.scrollTop;
|
2020-04-05 00:42:07 +08:00
|
|
|
let speed = top / 4;
|
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-05 00:42:07 +08:00
|
|
|
if (document.body.scrollHeight <= window.document.documentElement.clientHeight) {
|
|
|
|
scrollToTop.style.display = 'none';
|
|
|
|
}
|
2020-04-03 23:52:46 +08:00
|
|
|
|
|
|
|
|