Skip to content

Instantly share code, notes, and snippets.

@gkatsanos
Created January 9, 2017 11:50
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save gkatsanos/e3e80cc68f2c55d76d6338ae787a5d91 to your computer and use it in GitHub Desktop.
Save gkatsanos/e3e80cc68f2c55d76d6338ae787a5d91 to your computer and use it in GitHub Desktop.
const isElementInViewport = function (el) {
let rect = el.getBoundingClientRect()
return (
rect.top >= 0 &&
rect.left >= 0 &&
rect.bottom <= (window.innerHeight || document.documentElement.clientHeight) &&
rect.right <= (window.innerWidth || document.documentElement.clientWidth)
)
}
const getLogoElement = function () {
return document.getElementsByClassName('js-logo')[0]
}
const handleScroll = function () {
const rocketLogo = getLogoElement()
if (!isElementInViewport(rocketLogo)) {
jQuery('.header').addClass('header--scrolled')
} else {
jQuery('.header').removeClass('header--scrolled')
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment