Created
September 24, 2013 15:50
-
-
Save pketh/6686884 to your computer and use it in GitHub Desktop.
simple parallax scrolling using jquery
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
//simple version targetting a position: absolute div | |
$(window).on("scroll",function(){ | |
$('.target').css({"top" : ( .5 * $(window).scrollTop() ) + 100 }) | |
// the .5 refers to parallax speed (higher is faster) | |
// the 100 refers to the initial start position offset (higher is further down) | |
}) | |
// version with additional fading out as you scroll down | |
$('.target').css({"top" : ( .5 * $(window).scrollTop() ) , "opacity" : ($(window).height() / $(document).scrollTop() ) -.5 }) | |
// the -.5 adjusts the speed of opacity reduction as you scroll down (higher is faster) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment