From e10ed01eb1e23f583c4af499aee52214b220715f Mon Sep 17 00:00:00 2001 From: XPoet Date: Mon, 26 Oct 2020 10:42:33 +0800 Subject: [PATCH] fix: fixed infinite loop bug when scroll to bottom --- source/js/back2top.js | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/source/js/back2top.js b/source/js/back2top.js index 57e4f46..aba51f3 100644 --- a/source/js/back2top.js +++ b/source/js/back2top.js @@ -23,10 +23,10 @@ window.addEventListener('DOMContentLoaded', () => { back2Bottom() { let scrollHeight = document.body.scrollHeight || document.documentElement.scrollHeight; + let scrollTop = document.body.scrollTop || document.documentElement.scrollTop; const scrollBottomTimer = setInterval(function () { - let scrollTop = document.body.scrollTop || document.documentElement.scrollTop; if (!scrollTop) scrollTop = 10; - scrollTop = scrollTop + scrollTop / 2; + scrollTop = Math.floor(scrollTop + scrollTop / 2); window.scrollTo(0, scrollTop); if (scrollTop >= scrollHeight) { clearInterval(scrollBottomTimer); @@ -54,5 +54,3 @@ window.addEventListener('DOMContentLoaded', () => { ILS.utils.initBack2TopButton(); ILS.utils.initBack2BottomButton(); }); - -