Skip to content

Instantly share code, notes, and snippets.

@timramseyjr
Last active March 24, 2017 14:33
Show Gist options
  • Save timramseyjr/49df0144b366188818e431cd5513a89a to your computer and use it in GitHub Desktop.
Save timramseyjr/49df0144b366188818e431cd5513a89a to your computer and use it in GitHub Desktop.
Fade In Content when scrolling
$.fn.fadeInScroll = function(options) {
$(window).unbind('.checkFades');
var elements = $(this);
var settings = $.extend({
minDistance: 80 * $(window).height() / 100,
speed:500
}, options );
$(elements).each(function(){
$(this).css({opacity:0});
});
var checkFades = function(){
vWindowScrollTop = $(window).scrollTop();
$(elements).each(function(){
if(((vWindowScrollTop + parseInt(settings.minDistance)) >= $(this).offset().top) ){
$(this).animate({opacity:1},settings.speed);
}
});
}
$(window).bind('scroll.checkFades', checkFades);
$(window).scrollTop($(window).scrollTop()+1);
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment