Last active
December 28, 2015 16:39
-
-
Save andrezrv/7530179 to your computer and use it in GitHub Desktop.
How to slow the scrolling of an HTML element to create a simple parallax effect using jQuery.
This file contains 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
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