Created
January 9, 2017 11:50
-
-
Save gkatsanos/e3e80cc68f2c55d76d6338ae787a5d91 to your computer and use it in GitHub Desktop.
This file contains 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
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