Skip to content

Instantly share code, notes, and snippets.

@itsmikita
Last active August 17, 2020 18:23
Show Gist options
  • Save itsmikita/08fc87c28a42d25aa9ee6c7b324c96df to your computer and use it in GitHub Desktop.
Save itsmikita/08fc87c28a42d25aa9ee6c7b324c96df to your computer and use it in GitHub Desktop.
Insersection Observer API
( function() {
if( ( "undefined" !== typeof window.orientation ) || ( -1 !== navigator.userAgent.indexOf( "IEMobile" ) ) ) {
window.addEventListener( "load", function() {
var elements = document.querySelectorAll( ".people-item" );
var observer = new IntersectionObserver( function( entries ) {
entries.forEach( function( entry ) {
if( entry.isIntersecting ) {
entry.target.classList.add( "intersecting" );
}
else {
entry.target.classList.remove( "intersecting" );
}
} );
}, { threshold: [ 1.0 ] } );
document.querySelectorAll( ".people-item" ).forEach( function( element ) {
observer.observe( element );
} );
} );
}
} )();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment