From f4ae51623f58ab4c6e9c099111c26a5e7f102d7d Mon Sep 17 00:00:00 2001 From: Janis Hutz Date: Tue, 10 Sep 2024 09:31:40 +0200 Subject: [PATCH] circumvent browser bug for scroll component --- components/scroll/scroll.js | 29 +++++++++++++++++++++-------- 1 file changed, 21 insertions(+), 8 deletions(-) diff --git a/components/scroll/scroll.js b/components/scroll/scroll.js index ac6cd1d..db6f6fa 100644 --- a/components/scroll/scroll.js +++ b/components/scroll/scroll.js @@ -29,14 +29,8 @@ window.scrollHint = ( maxScroll ) => { timeout = setTimeout( () => { showHint() }, 2500 ); } - document.onscrollend = () => { - scrollCorrectionTimeout = setTimeout( () => { - scrollCorrection(); - }, 1000 ); - timeout = setTimeout( () => { - showHint(); - }, 2500 ); - } + let lastScrollTimeStamp = new Date().getTime(); + let scrollInterval = 0; document.onscroll = () => { try { clearTimeout( timeout ); @@ -49,6 +43,25 @@ window.scrollHint = ( maxScroll ) => { el.classList.remove( 'show-scroll' ); el.classList.add( 'hide-scroll' ); } + + if ( scrollInterval === 0 ) { + scrollInterval = setInterval( () => { + if ( lastScrollTimeStamp < new Date().getTime() + 500 ) { + scrollCorrectionTimeout = setTimeout( () => { + scrollCorrection(); + }, 1000 ); + timeout = setTimeout( () => { + showHint(); + }, 2500 ); + try { + clearInterval( scrollInterval ); + scrollInterval = 0; + } catch ( e ) { /* empty */ } + } + }, 250 ); + } + + lastScrollTimeStamp = new Date().getTime(); }; window.onresize = () => {