Last active
June 1, 2016 21:23
-
-
Save tpitre/0d829f233c2e58e63b70899c98b64a6e to your computer and use it in GitHub Desktop.
Simple Parallax Effect
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
// Is it a touch device? (requires Modernizr) | |
var isTouch = (Modernizr.touch) ? true : false; | |
// Background image parallax. | |
var parallax = function($b) { | |
if (!isTouch) { | |
var scrolled = $(window).scrollTop(); | |
$b.css('background-position', 'center ' + -(scrolled * 0.5) + 'px'); | |
} | |
} | |
$(window).scroll(function() { | |
// Init parallax on element with background image when scrolling. | |
parallax($('.hero__image')); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment