Created
December 12, 2014 03:44
-
-
Save afestein/19e64b77b4537c3c70a6 to your computer and use it in GitHub Desktop.
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
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