From af3d72ad7501f5329b18bf90f6e4aaa8cd58085e Mon Sep 17 00:00:00 2001 From: alistair3149 Date: Sat, 25 May 2024 19:53:17 -0400 Subject: [PATCH] =?UTF-8?q?fix(core):=20=F0=9F=90=9B=20incorrect=20sticky?= =?UTF-8?q?=20header=20class=20assignment?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- resources/skins.citizen.scripts/skin.js | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/resources/skins.citizen.scripts/skin.js b/resources/skins.citizen.scripts/skin.js index 9f879de2..bc3eae74 100644 --- a/resources/skins.citizen.scripts/skin.js +++ b/resources/skins.citizen.scripts/skin.js @@ -34,8 +34,8 @@ function initStickyHeader( document ) { const addScrollDownClass = toggleScrollClass( SCROLL_UP_CLASS, SCROLL_DOWN_CLASS ); const addScrollUpClass = toggleScrollClass( SCROLL_DOWN_CLASS, SCROLL_UP_CLASS ); - const toggleStickyClass = () => { - return ( state ) => { + const toggleStickyClass = ( state ) => { + return () => { window.requestAnimationFrame( () => { document.body.classList.toggle( STICKY_CLASS, state ); } ); @@ -45,8 +45,9 @@ function initStickyHeader( document ) { initDirectionObserver( addScrollDownClass, addScrollUpClass, 10 ); const sentinel = document.getElementById( STICKY_SENTINEL_ID ); + const shouldStickyHeader = sentinel && getComputedStyle( sentinel ).getPropertyValue( 'display' ) !== 'none'; - if ( sentinel && getComputedStyle( sentinel ).getPropertyValue( 'display' ) !== 'none' ) { + if ( shouldStickyHeader ) { const observer = initIntersectionObserver( toggleStickyClass( true ), toggleStickyClass( false ) ); observer.observe( sentinel ); }