Created
May 9, 2012 04:54
-
-
Save ScottPhillips/2641904 to your computer and use it in GitHub Desktop.
Fade in on Scroll
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).ready(function() { | |
/* Hide all elements outside the visible window */ | |
$('body *').each( function(){ | |
var top_of_object = $(this).position().top; | |
var bottom_of_window = $(window).scrollTop() + $(window).height(); | |
if( bottom_of_window < top_of_object ){ | |
$(this).addClass('hideme').css({'opacity':'0'}); | |
} | |
}); | |
/* Every time the window is scrolled ... */ | |
$(window).scroll( function(){ | |
/* Check the location of the desired elements */ | |
$('.hideme').each( function(i){ | |
var bottom_of_object = $(this).position().top + $(this).outerHeight(); | |
var bottom_of_window = $(window).scrollTop() + $(window).height(); | |
if( bottom_of_window > ( bottom_of_object + 20 ) ){ | |
$(this).removeClass('hideme').animate({'opacity':'1'},500); | |
} | |
}); | |
}); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment