Apologies for any similarity to other questions on this topic. I have searched extensively, but any assistance would be greatly appreciated.
I am utilizing a new animation library from Animista to animate specific elements on a test website. Animating elements upon page load is not an issue, but I am unsure how to make them trigger as they become visible, as is common on many websites nowadays.
For instance;
.bounce-in-top {
-webkit-animation: bounce-in-top 1.1s both;
animation: bounce-in-top 1.1s both;
}
@-webkit-keyframes bounce-in-top {
0% {
-webkit-transform: translateY(-500px);
transform: translateY(-500px);
-webkit-animation-timing-function: ease-in;
animation-timing-function: ease-in;
opacity: 0;
}
38% {
-webkit-transform: translateY(0);
transform: translateY(0);
-webkit-animation-timing-function: ease-out;
animation-timing-function: ease-out;
opacity: 1;
}
55% {
-webkit-transform: translateY(-65px);
transform: translateY(-65px);
-webkit-animation-timing-function: ease-in;
animation-timing-function: ease-in;
}
...
.trigger {
/* The plan was to add this to all elements and then trigger animations each time the class is in the viewport*/
}
<h1 class="bounce-in-top trigger">Page title, animates on load</h1>
...
<h2 class="bounce-in-top trigger">Lower down, should animate when visible</h2>
The animation is applied to both header 1 and header 2, but the header 2 animation runs before it's visible to the user.
.bounce-in-top {
-webkit-animation: bounce-in-top 1.1s both;
animation: bounce-in-top 1.1s both;
}
@-webkit-keyframes bounce-in-top {
...
.trigger {
/* The plan was to add this to all elements and then trigger animations each time the class is in the viewport*/
}
<h1 class="bounce-in-top trigger">Page title, animates on load</h1>
...
<h2 class="bounce-in-top trigger">Lower down, should animate when visible</h2>
I would like to use some form of query selector so that every time an element to be animated appears, its animation would run.
Any guidance and functional code would be immensely appreciated as I am struggling to implement this.
Thank you in advance.