Last active
November 22, 2017 18:27
-
-
Save drdogbot7/92b8f0d1523bb8ea389a3edec81649c9 to your computer and use it in GitHub Desktop.
Are we sticky yet?
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 areWeStickyYet( selector ) { | |
var stickyThing = document.querySelector( selector ); | |
var CSSTop = parseInt( getComputedStyle( stickyThing, null ).getPropertyValue("top"), 10); | |
window.addEventListener( 'scroll', function() { | |
if ( stickyThing.getBoundingClientRect().top <= CSSTop ) { | |
stickyThing.classList.add('is_sticky'); | |
return | |
} | |
stickyThing.classList.remove('is_sticky'); | |
}); | |
}; | |
module.exports = areWeStickyYet; | |
export default areWeStickyYet; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment