Skip to content

Instantly share code, notes, and snippets.

@danielbehrendt
Forked from rmdort/jquery.parallax.js
Created April 16, 2013 09:43
Show Gist options
  • Save danielbehrendt/5394703 to your computer and use it in GitHub Desktop.
Save danielbehrendt/5394703 to your computer and use it in GitHub Desktop.
$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