Created
June 6, 2019 14:47
-
-
Save fidlerryan/3fa59eac207528381f7456e6c2c2ebdf to your computer and use it in GitHub Desktop.
Sentinels
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const menuPrimary = document.getElementById( 'menu-primary' ); | |
const sentinelPrimary = document.querySelector( '.sentinel-primary' ); | |
function handlerPrimary( entriesPrimary ){ | |
entriesPrimary.forEach( function( entry ){ | |
if( entry.isIntersecting ){ | |
menuPrimary.classList.remove( 'sticky' ); | |
} else { | |
menuPrimary.classList.add( 'sticky' ); | |
} | |
}); | |
} | |
const observerPrimary = new window.IntersectionObserver( handlerPrimary ); | |
observerPrimary.observe( sentinelPrimary ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment