Created
January 16, 2013 16:38
-
-
Save rmdort/4548662 to your computer and use it in GitHub Desktop.
A simple jquery parallax
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
$window = $(window); | |
$('section').each(function(){ | |
var $this = $(this); // assigning the object | |
var off = $this.offset().top; | |
$this.data("top", off); | |
$(window).bind('resize scroll', function() { | |
// Scroll the background at var speed | |
// the yPos is a negative value because we're scrolling it UP! | |
var yPos = -(($window.scrollTop() - $this.offset().top) / 5); | |
// Put together our final background position | |
var coords = '50% '+ yPos + 'px'; | |
// Move the background | |
$this.css({ backgroundPosition: coords }); | |
}); // window scroll Ends | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment