hexo-theme-keep/source/js/scroll-to-top.js

16 lines
480 B
JavaScript
Raw Normal View History

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-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);
});