Skip to content

Instantly share code, notes, and snippets.

@pketh
Created September 24, 2013 15:50
Show Gist options
  • Save pketh/6686884 to your computer and use it in GitHub Desktop.
Save pketh/6686884 to your computer and use it in GitHub Desktop.
simple parallax scrolling using jquery
//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