Skip to content

Instantly share code, notes, and snippets.

@afestein
Created December 12, 2014 03:44
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save afestein/19e64b77b4537c3c70a6 to your computer and use it in GitHub Desktop.
Save afestein/19e64b77b4537c3c70a6 to your computer and use it in GitHub Desktop.
Parallax
function parallax(element) {
var offset = 1;
// Determine whether scrolling up or scrolling down
var st = $(this).scrollTop();
if (st < lastScrollTop){
offset = offset * -1;
}
lastScrollTop = st;
var pos = element.css('background-position').split(" ");
pos[0] = parseInt(pos[0].replace("%","").replace("px",""));
pos[1] = parseInt(pos[1].replace("%","").replace("px","")) - offset;
newpos = pos[0] + 'px ' + pos[1] + 'px';
$('#opacityMask').css('background-position', newpos)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment