Skip to content

Instantly share code, notes, and snippets.

@eljamez
Last active December 31, 2015 08:49
Show Gist options
  • Save eljamez/7962995 to your computer and use it in GitHub Desktop.
Save eljamez/7962995 to your computer and use it in GitHub Desktop.
Quick bit for initiating a background image paralax on a large image (hero) that is at the top of your page. (NEEDS WORK)
# Still working on this.
# the element with the class 'hero-paralax' will be targeted, setting the variable
$hero_paralax = $('.hero-paralax')
# watching for scrolling
$(@).scroll () =>
# set scroll top position
scroll_top = $(@).scrollTop()
# set new bg position (moves down at half the speed of scrolling
paralax_hero_bg_position = scroll_top / 2
# set the background position
$hero_paralax.css {'background-position':'0px '+paralax_hero_bg_position+'px'}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment