Created
November 21, 2012 18:30
-
-
Save lipelopeslage/4126702 to your computer and use it in GitHub Desktop.
My parallax secret
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
/*########################################################################*/ | |
/*###### using jQuery selector for a fast/cross-browser resolution #######*/ | |
/*########################################################################*/ | |
var totalAreas = 6, // this value is obviously arbitrary | |
winH = $(window).height, // the window height | |
top = $(window).scrollTop(), // the current scroll value | |
maxScroll = $(document).height() - winH, // the maximum scroll value | |
scrollPerc = top/maxScroll, // the current scroll percentage | |
areaPercent = 0; // init variable | |
// just logging the percentage, from here is up to you | |
function logPercent(index, percent) { | |
console.log("Area index: "+index+" is "+percent+"%. Calculate proportions!"); | |
} | |
/* calculate the percentage from each area */ | |
for(var i = 0; i < totalAreas; i++){//######### here is the catch: the percent of the total scroll times the total of areas minus the current index, plus one :) | |
areaPercent = 1 + ((scrollPerc * totalAreas) - i); | |
logPercent(i, areaPercent); // loggin result | |
} | |
//###################################################################### | |
//##### PS: Assuming the areas has the same height, the window height |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
LIVE EXAMPLE AT: www.fullsocialwifi.com.br