Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save fidlerryan/3fa59eac207528381f7456e6c2c2ebdf to your computer and use it in GitHub Desktop.
Save fidlerryan/3fa59eac207528381f7456e6c2c2ebdf to your computer and use it in GitHub Desktop.
Sentinels
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