Skip to content

Instantly share code, notes, and snippets.

@drdogbot7
Last active November 22, 2017 18:27
Show Gist options
  • Save drdogbot7/92b8f0d1523bb8ea389a3edec81649c9 to your computer and use it in GitHub Desktop.
Save drdogbot7/92b8f0d1523bb8ea389a3edec81649c9 to your computer and use it in GitHub Desktop.
Are we sticky yet?
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