Skip to content

Instantly share code, notes, and snippets.

@imjn
Last active April 22, 2019 06:17
Show Gist options
  • Save imjn/1e9e5c5307bfc4d354d9499290348f2b to your computer and use it in GitHub Desktop.
Save imjn/1e9e5c5307bfc4d354d9499290348f2b to your computer and use it in GitHub Desktop.
Fade in with scroll
function scroll_fadein(){
jQuery('.fadein').each(function(){
var elemPos = jQuery(this).offset().top;
var scroll = jQuery(window).scrollTop();
var windowHeight = jQuery(window).height();
if (scroll > elemPos - windowHeight + 60){
jQuery(this).addClass('scrollin');
}
});
}
// CSS
.fadein {
opacity : 0.0;
transform : translate(0, 30px);
transition : all 500ms;
}
.fadein.scrollin {
opacity : 1;
transform : translate(0, 0);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment