Last active
November 19, 2015 23:24
-
-
Save jobayerarman/a54bf8d45e5b75de43a5 to your computer and use it in GitHub Desktop.
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
| /* Parallax Scrolling */ | |
| $(function parallaxScrolling() { | |
| $window = $(window); // Cache the Window object | |
| var width = $window.width(); // Cache the window width | |
| var $bgobj = $('.parallax'); // assigning the object | |
| $('.parallax').each(function(){ | |
| var $bgobj = $(this); // assigning the object | |
| $(window).scroll(function() { | |
| // Scroll the background at var speed | |
| // the yPos is a negative value because we're scrolling it UP! | |
| var yPos = Math.round(-($window.scrollTop() / $bgobj.data('speed'))); | |
| // Put together our final background position | |
| var coords = '50% '+ yPos + 'px'; | |
| // Move the background only on desktop | |
| if(width > 768) { | |
| $bgobj.css({ backgroundPosition: coords }); | |
| } | |
| }); // window scroll Ends | |
| }); | |
| }); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment