Last active
March 24, 2017 14:33
-
-
Save timramseyjr/49df0144b366188818e431cd5513a89a to your computer and use it in GitHub Desktop.
Fade In Content when scrolling
This file contains 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
$.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