Created
November 16, 2012 04:48
-
-
Save colllin/4084171 to your computer and use it in GitHub Desktop.
Temp
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
| $(document).scroll(function() { | |
| var currentScrollTop = $(this).scrollTop(); | |
| if (currentScrollTop > prevScrollTop) { | |
| //down | |
| var lasthiddenbox = $('.fadeboxhidden:last'); | |
| var nextbox = (lasthiddenbox.length > 0) ? lasthiddenbox.next('.fadebox') : $('.fadebox:first'); | |
| while (nextbox.length) { | |
| if (nextbox.offset().top < currentScrollTop) { | |
| nextbox.css('opacity', (currentScrollTop - nextbox.offset().top) / nextbox.outerHeight()); | |
| } | |
| if ((nextbox.offset().top + nextbox.outerHeight()) < currentScrollTop) | |
| nextbox = nextbox.next('.fadebox'); | |
| } | |
| } else { | |
| //up | |
| } | |
| prevScrollTop = currentScrollTop ; | |
| }); | |
| //create an object to hold a list of box top locations | |
| var boxtops = new Object; | |
| //track whether user has scrolled up or down | |
| var prevScrollTop = $(document).scrollTop(); | |
| //gather all boxes and store their top location | |
| $('.fadebox').each( function(index) { | |
| //you may want to dynamically generate div ids here based on index. I didn't do this | |
| //because i was already using the id for positioning. | |
| var divid = $(this).prop('id'); | |
| boxtops[divid] = $(this).offset().top; | |
| //console.log(boxtops[divid]); | |
| }); | |
| |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment