I'd like to make something like this.
CSS library Animate.css
@keyframes fadeInUp {
from {
opacity: 0;
-webkit-transform: translate3d(0, 100%, 0);
transform: translate3d(0, 100%, 0);
}
to {
opacity: 1;
-webkit-transform: translate3d(0, 0, 0);
transform: translate3d(0, 0, 0);
}
}
.animate__fadeInUp {
-webkit-animation-name: fadeInUp;
animation-name: fadeInUp;
}
.animate__animated {
animation-duration: 1s;
animation-fill-mode: both;
}
HTML
<div class="animatedScroll animate__animated animate__fadeInUp" style="animation-delay: 0.3s;"><p>111</p></div>
<div class="animatedScroll"><p>222</p></div>
jQuery
$(function(){
var element = $('.animatedScroll');
$.each(element, function(i){
let ele = $(this);
var hasAnimation = false;
var name = '';
$(this).on('animationstart', function(e){
// If the element has an animation and it's start running
hasAnimation = true;
name = e.originalEvent.animationName;
});
if ( hasAnimation === true ) {
console.log('animation name is : ' + name);
}
else {
console.log('no animation');
}
});
})
I'm expecting the console log is animation name is : fadeInUp and no animation.
But the result is no animation for both element.
As far as i know it's because event animationstart fire off late.
Is there any other way to achive same goal? And can this be solve with deferred object?