Skip to content

Instantly share code, notes, and snippets.

@andrezrv
Last active Dec 28, 2015
Embed
What would you like to do?
How to slow the scrolling of an HTML element to create a simple parallax effect using jQuery.
jQuery( document ).ready( function( $ ) {
var scrollable = $('#branding .navbar-inner');
var difference = 5;
if ( scrollable.length ) {
var a = document.body;
var e = document.documentElement;
$( window ).unbind( 'scroll' ).scroll( function () {
scrollable.css( 'background-position', '0px ' + -( Math.max( e.scrollTop, a.scrollTop ) / difference ) + 'px' );
} );
}
} );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment