Last active
December 31, 2015 08:49
-
-
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)
This file contains hidden or 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
# 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