Skip to content

Instantly share code, notes, and snippets.

@walidvb
Last active May 18, 2016 11:43
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 walidvb/1c22fa9498b39b00a612a88d128cc7c2 to your computer and use it in GitHub Desktop.
Save walidvb/1c22fa9498b39b00a612a88d128cc7c2 to your computer and use it in GitHub Desktop.
Parralax background image
var $elem = $('.has-background-image');
function parallax() {
var top = $elem.offset().top;
if((pos = (top-window.scrollY))-window.innerHeight <= 0)
{
var yPos = pos * 0.15;
var coords = "50% "+yPos+"px";
$elem.css("backgroundPosition", coords);
}
};
$(window).on('scroll', parallax);
parallax();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment