(This page includes affiliate links. If you click and purchase, I receive a small commission at no extra cost from you and that way you can support me. I only recommend tools that I have personally used and loved.)
Support by getting –
1 – Elementor Pro
Video Coming Soon.
JS code to play CSS animation or CSS transition when in view
- Add “dm-view” CSS class to the elements that have animations/transitions needed to play in view.
- Now add .animate to CSS which would contain the animation/transition values. Example: if “.flower” is my element’s CSS class, then create “.flower.animate” and add new transition values or animation in it.
- The Javascript code works by adding .animate to your element’s CSS when it is in viewport and removes .animate when out of viewport.
- If you wish to not remove .animate when out of viewport so that the animation only plays once, you can remove “else” condition from javascript. i.e Remove this code -> else { entry.target.classList.remove(‘animate’);}
CSS animation
CSS transition
Plays only once
Add your animated stuff here
Add your animated stuff here
/*Make sure to add extra "dm-view" class to element that needs animation in view*/
.flower-icon {
opacity: 0;
transition: 1s;
}
/*You can add CSS animation or CSS transitions below and it will work for both*/
.flower-icon.animate{
animation: fade-scale 2s ease forwards;
}
@keyframes fade-scale {
0% {
scale:0;
opacity:0;
}
100% {
scale:1;
opacity:1;
}
}
/*CSS Transition Version*/
.flower-icon2 {
opacity: 0;
transition: 1s;
scale: 0;
}
.flower-icon2.animate{
scale: 1;
opacity: 1;
}