I'm using animate.css CSS3 animations and I want them to show up as you scroll down the page. I ran into a problem and cannot figure it out.
I use the following script from a website:
$(window).scroll(function() {
$('#animatedElement').each(function(){
var imagePos = $(this).offset().top;
var topOfWindow = $(window).scrollTop();
if (imagePos < topOfWindow+400) {
$(this).addClass("slideUp");
}
});
});
I modified it a little bit to this:
$(window).scroll(function() {
$('.hidden').each(function(){
var imagePos = $(this).offset().top;
var topOfWindow = $(window).scrollTop();
if (imagePos < topOfWindow+400) {
$(this).removeClass("hidden").addClass("animated");
}
});
});
I want to hide the elements until they are in the visible area of the website and I give them a class called "hidden" with opacity: 0 or visibility: hidden.
Even though the script successfully removes the "hidden"-class and adds the "animated"-class, there is no animation going on, the element just appears.
I thought that it has something to do with the css of the "hidden"-class, but even if I define nothing under this class, there are no animations.
If I change the script to add a specific animation-class insted of the "animated"-class, it works, but only without the "hidden"-class.
I hope you understand what I mean, it is quite hard to explain, so I made a fiddle.
However, I want the script to work with different animations and not only one like in the fiddle.
I really cannot figure this out, so I really appreciate any help. Thanks!