Created
October 16, 2013 18:24
-
-
Save boertel/7012425 to your computer and use it in GitHub Desktop.
Parallax for the header
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
| var hero = document.getElementById("header"), | |
| heroHeight = $(hero).outerHeight(); | |
| function updateScroll() { | |
| scrollAmount = $(window).scrollTop(); | |
| if (scrollAmount <= heroHeight) { | |
| hero.style['-webkit-transform'] = 'translate3d(0, ' + (scrollAmount / 2) + 'px, 0)'; | |
| } else if (scrollAmount <= heroHeight) { | |
| $(self).css('top', (scrollAmount / 2) + 'px'); | |
| } | |
| } | |
| window.onscroll = function () { | |
| updateScroll(); | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment