Last active
August 17, 2020 18:23
-
-
Save itsmikita/08fc87c28a42d25aa9ee6c7b324c96df to your computer and use it in GitHub Desktop.
Insersection Observer API
This file contains hidden or 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
( 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