Skip to content

Instantly share code, notes, and snippets.

@jackmcdade
Created January 23, 2014 16:46
Show Gist options
  • Save jackmcdade/8582127 to your computer and use it in GitHub Desktop.
Save jackmcdade/8582127 to your computer and use it in GitHub Desktop.
parallax js
// Just a little vertical parllax goodness.
// You can play with the offsets for a more dramatic effect if you'd like.
$(function() {
var $window = $(window);
if ($window.width() > 640) {
$('.parallax').each(function() {
var self = $(this);
$(window).scroll(function() {
var offset = 70, // A little padding above the image to be safe
yPos = ($window.scrollTop() / 3) - 70,
coordinates = '50% '+ yPos + 'px';
self.css({ backgroundPosition: coordinates });
});
});
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment