diff --git a/resources/skins.citizen.scripts/scrollObserver.js b/resources/skins.citizen.scripts/scrollObserver.js index 537cfc1e..be850c04 100644 --- a/resources/skins.citizen.scripts/scrollObserver.js +++ b/resources/skins.citizen.scripts/scrollObserver.js @@ -29,27 +29,6 @@ function initDirectionObserver( onScrollDown, onScrollUp, threshold ) { window.addEventListener( 'scroll', throttledOnScroll ); } -/** - * Create an observer based on element visiblity. - * Based on Vector - * - * @param {Function} onHidden functionality for when the element is visible - * @param {Function} onVisible functionality for when the element is hidden - * @return {IntersectionObserver} - */ -function initIntersectionObserver( onHidden, onVisible ) { - /* eslint-disable-next-line compat/compat */ - return new IntersectionObserver( ( [ entry ] ) => { - if ( entry.isIntersecting ) { - // Viewport is within the target element. - onVisible(); - } else if ( entry.boundingClientRect.top < 0 ) { - // Viewport has crossed the bottom edge of the target element. - onHidden(); - } - } ); -} - /** * Create an observer for showing/hiding feature and for firing scroll event hooks. * @@ -72,6 +51,5 @@ function initScrollObserver( show, hide ) { module.exports = { initDirectionObserver, - initIntersectionObserver, initScrollObserver }; diff --git a/resources/skins.citizen.scripts/stickyHeader.js b/resources/skins.citizen.scripts/stickyHeader.js index 9cc4d5c8..1cef9f99 100644 --- a/resources/skins.citizen.scripts/stickyHeader.js +++ b/resources/skins.citizen.scripts/stickyHeader.js @@ -1,7 +1,7 @@ const SCROLL_DOWN_CLASS = 'citizen-scroll--down'; const SCROLL_UP_CLASS = 'citizen-scroll--up'; const STICKY_CLASS = 'citizen-page-header--sticky'; -const { initDirectionObserver, initIntersectionObserver } = require( './scrollObserver.js' ); +const { initDirectionObserver, initScrollObserver } = require( './scrollObserver.js' ); /** * Observes the scroll direction and adds/removes corresponding classes to the body element. @@ -84,7 +84,7 @@ function init() { toggleStickyHeader( true ); }, 250 ); - const observer = initIntersectionObserver( + const observer = initScrollObserver( () => { toggleStickyHeader( true ); window.addEventListener( 'resize', onResize );