Created
February 8, 2013 10:41
-
-
Save maylogger/4738028 to your computer and use it in GitHub Desktop.
js 圖片視差滾動機制
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 | |
| /////////////////////////////// | |
| // Calcualte the home banner parallax scrolling | |
| function scrollBanner() { | |
| //Get the scoll position of the page | |
| scrollPos = $(this).scrollTop(); | |
| //Scroll and fade out the banner text | |
| $('#bannerText').css({ | |
| 'margin-top' : -(scrollPos/3)+"px", | |
| 'opacity' : 1-(scrollPos/300) | |
| }); | |
| //Scroll the background of the banner | |
| $('#homeBanner').css({ | |
| 'background-position' : 'center ' + (-scrollPos/8)+"px" | |
| }); | |
| } | |
| /////////////////////////////// | |
| // Initialize | |
| /////////////////////////////// | |
| $(document).ready(function(){ | |
| if(!isMobile()) { | |
| $(window).scroll(function() { | |
| scrollBanner(); | |
| }); | |
| } | |
| }); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment