Last active
July 31, 2019 14:53
-
-
Save Trovin/5fcd216ee7da379d2905e7d50a8266a0 to your computer and use it in GitHub Desktop.
JS animate el on scroll
This file contains hidden or 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
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