Skip to content

Instantly share code, notes, and snippets.

@taniarascia
Created September 16, 2015 19:03
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save taniarascia/b61d0f08bee2150c151e to your computer and use it in GitHub Desktop.
Save taniarascia/b61d0f08bee2150c151e to your computer and use it in GitHub Desktop.
Fade Items Into View on Scroll
$(window).scroll(function () {
/* Check the location of each desired element */
$('.fade').each(function (i) {
var bottom_of_object = $(this).offset().top + $(this).outerHeight();
var bottom_of_window = $(window).scrollTop() + $(window).height();
/* If the object is completely visible in the window, fade it in */
if (bottom_of_window > bottom_of_object) {
$(this).animate({
'opacity': '1'
}, 500);
}
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment