Last active
May 18, 2016 11:43
-
-
Save walidvb/1c22fa9498b39b00a612a88d128cc7c2 to your computer and use it in GitHub Desktop.
Parralax background image
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
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