Instantly share code, notes, and snippets.

Embed
What would you like to do?
Simple parallax
/**
* Listen for scrolling events
* Note:
* - This is for parallax in header-containers only.
* - Requires jQuery
*/
jQuery(document).on('scroll', function () {
/* Get current scroll-value */
var ScrollTop = jQuery(document).scrollTop();
/* Here comes the magic */
jQuery('.container-with-background-image').css('background-position', '0px ' + parseFloat(ScrollTop / 2) + 'px');
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment