Hey Paul,
I am posting the code below…
It is a code that is meant to show/hide the header - on scroll up/ down - and it IS working, in general - the only issue is, if the scroll AMOUNT is very small, then the page keeps jumping up and down - and so, the header keeps showing & hiding - even a console log comes up, as “UP”-“DOWN”-“UP”-“DOWN”… even when there’s no actual scroll happening!
If you scroll MORE, in one go, then the code plays out fine!
The code is placed in the masterPage.js.
// START CODE ~ show/hide header on scroll up/down
function show_Header ( ) {
$w ( “#header1” ). children . forEach (( item , i ) => {
item . expand ();
})
}
function hide_Header ( ) {
$w ( “#header1” ). children . forEach (( item , i ) => {
item . collapse ();
})
}
import wixWindow from ‘wix-window’ ;
var scrollDirection
var scrollPosition = 0
var scrollInterval = 2000 //The lower the scrollInterval, the more precise will be the scroll-position.
$w . onReady (() => { setInterval (() => show_scrollPosition (), scrollInterval ); })
function show_scrollPosition ( ) {
wixWindow . getBoundingRect ()
. then (( windowSizeInfo ) => {
let scrollX = windowSizeInfo . scroll . x ;
let scrollY = windowSizeInfo . scroll . y ;
console . log ( scrollX , scrollY )
if (( scrollPosition !== windowSizeInfo . scroll . y ) && ( wixWindow . formFactor !== “Mobile” )) {
**if** ( scrollPosition < windowSizeInfo . scroll . y ) {
scrollDirection = "DOWN" , console . log ( scrollDirection ), hide_Header (), $w ( '#box47' ). show ()
}
**if** ( scrollPosition > windowSizeInfo . scroll . y ) {
scrollDirection = "UP" , console . log ( scrollDirection ), show_Header (), $w ( '#box47' ). hide ()
} **else if** ( scrollY === 0 ) {
show_Header ();
}
scrollPosition = windowSizeInfo . scroll . y ;
}
});
}
// END CODE ~ show/hide header on scroll up/down
This same issue had happened once earlier - then, I had created a duplicate for the site and that had mysteriously solved the problem!
It’s NOT solving the problem now…
Thanks in advance!