2020-10-21 19:36:38 +08:00
|
|
|
window.addEventListener('DOMContentLoaded', () => {
|
|
|
|
ILS.utils = {
|
|
|
|
|
|
|
|
...ILS.utils,
|
|
|
|
|
|
|
|
back2TopButton_dom: document.querySelector('.scroll-to-top'),
|
2020-10-25 10:48:07 +08:00
|
|
|
back2BottomButton_dom: document.querySelector('.scroll-to-bottom'),
|
2020-10-21 19:36:38 +08:00
|
|
|
|
|
|
|
back2top() {
|
|
|
|
const scrollTopTimer = setInterval(function () {
|
|
|
|
let top = document.body.scrollTop || document.documentElement.scrollTop;
|
|
|
|
let speed = top / 2;
|
|
|
|
if (document.body.scrollTop !== 0) {
|
|
|
|
document.body.scrollTop -= speed;
|
|
|
|
} else {
|
|
|
|
document.documentElement.scrollTop -= speed;
|
|
|
|
}
|
|
|
|
if (top === 0) {
|
|
|
|
clearInterval(scrollTopTimer);
|
|
|
|
}
|
|
|
|
}, 30);
|
|
|
|
},
|
|
|
|
|
2020-10-25 10:48:07 +08:00
|
|
|
back2Bottom() {
|
|
|
|
let scrollHeight = document.body.scrollHeight || document.documentElement.scrollHeight;
|
|
|
|
const scrollBottomTimer = setInterval(function () {
|
|
|
|
let scrollTop = document.body.scrollTop || document.documentElement.scrollTop;
|
|
|
|
if (!scrollTop) scrollTop = 10;
|
|
|
|
scrollTop = scrollTop + scrollTop / 2;
|
|
|
|
window.scrollTo(0, scrollTop);
|
|
|
|
if (scrollTop >= scrollHeight) {
|
|
|
|
clearInterval(scrollBottomTimer);
|
|
|
|
}
|
|
|
|
}, 50);
|
|
|
|
},
|
|
|
|
|
2020-10-21 19:36:38 +08:00
|
|
|
initBack2TopButton() {
|
|
|
|
if (ILS.utils.back2TopButton_dom) {
|
|
|
|
ILS.utils.back2TopButton_dom.addEventListener('click', () => {
|
|
|
|
this.back2top();
|
|
|
|
});
|
|
|
|
}
|
|
|
|
},
|
2020-10-25 10:48:07 +08:00
|
|
|
|
|
|
|
initBack2BottomButton() {
|
|
|
|
if (ILS.utils.back2BottomButton_dom) {
|
|
|
|
ILS.utils.back2BottomButton_dom.addEventListener('click', () => {
|
|
|
|
this.back2Bottom();
|
|
|
|
});
|
|
|
|
}
|
|
|
|
},
|
2020-10-21 19:36:38 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
ILS.utils.initBack2TopButton();
|
2020-10-25 10:48:07 +08:00
|
|
|
ILS.utils.initBack2BottomButton();
|
2020-10-21 19:36:38 +08:00
|
|
|
});
|
|
|
|
|
|
|
|
|