Skip to content

Instantly share code, notes, and snippets.

@colllin
Created November 16, 2012 04:48
Show Gist options
  • Select an option

  • Save colllin/4084171 to your computer and use it in GitHub Desktop.

Select an option

Save colllin/4084171 to your computer and use it in GitHub Desktop.
Temp
$(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