diff options
Diffstat (limited to 'p/scripts/main.js')
| -rw-r--r-- | p/scripts/main.js | 25 |
1 files changed, 14 insertions, 11 deletions
diff --git a/p/scripts/main.js b/p/scripts/main.js index 42d7aeef4..4ddafb2bd 100644 --- a/p/scripts/main.js +++ b/p/scripts/main.js @@ -735,20 +735,23 @@ function onScroll() { } } +let lastScroll = 0; // Throttle +let timerId = 0; +function debouncedOnScroll() { + clearTimeout(timerId); + if (lastScroll + 500 < Date.now()) { + lastScroll = Date.now(); + onScroll(); + } else { + timerId = setTimeout(onScroll, 500); + } +} + function init_posts() { if (context.auto_load_more || context.auto_mark_scroll || context.auto_remove_article) { box_to_follow = context.current_view === 'global' ? document.getElementById('panel') : document.scrollingElement; - let lastScroll = 0; // Throttle - let timerId = 0; - (box_to_follow === document.scrollingElement ? window : box_to_follow).onscroll = function () { - clearTimeout(timerId); - if (lastScroll + 500 < Date.now()) { - lastScroll = Date.now(); - onScroll(); - } else { - timerId = setTimeout(onScroll, 500); - } - }; + (box_to_follow === document.scrollingElement ? window : box_to_follow).onscroll = debouncedOnScroll; + window.addEventListener('resize', debouncedOnScroll); onScroll(); } |
