Skip to content

Instantly share code, notes, and snippets.

@Trovin
Last active July 31, 2019 14:53
Show Gist options
  • Save Trovin/5fcd216ee7da379d2905e7d50a8266a0 to your computer and use it in GitHub Desktop.
Save Trovin/5fcd216ee7da379d2905e7d50a8266a0 to your computer and use it in GitHub Desktop.
JS animate el on scroll
function animateEl(animEl) {
let counter = 0.2,
animArray = animEl;
animArray.each(function(index, value) {
counter += 0.2;
$(value).css('transition-delay', `${counter}s`);
let targetPos = $(value).offset().top,
winHeight = $(window).height(),
scrollToElem = targetPos - (winHeight / 1.2);
$(window).scroll(function() {
let winScrollTop = $(this).scrollTop();
if(winScrollTop > scrollToElem) {
$(value).addClass('trust__logo-image--showing');
}
});
});
}
let elements = $('.trust__logo-image');
animateEl(elements);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment