Skip to content

Instantly share code, notes, and snippets.

@boertel
Created October 16, 2013 18:24
Show Gist options
  • Select an option

  • Save boertel/7012425 to your computer and use it in GitHub Desktop.

Select an option

Save boertel/7012425 to your computer and use it in GitHub Desktop.
Parallax for the header
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