My flexbox contains 4 images, each triggering an animation on hover. However, the animation stops if I hover over the same image again.
I have tried various JavaScript solutions found online to restart the animation, but none seem to be working for me.
Should I target the span by its ID and add/remove the "textAnim" class using JavaScript? And how can this be done when hovering over the image?
/* Images Section Styling */
.container-3 {
display: flex;
flex-wrap: nowrap;
justify-content: space-between;
position: relative;
}
.container-3 img {
max-width: 100%;
max-height: 100%;
}
.image {
position: relative;
max-width: 100%;
max-height: 100%;
}
/* Image overlay */
.overlay {
position: absolute;
display: flex;
top: 0;
left: 0;
width: 100%;
height: 100%;
color: rgba(255, 255, 255, 0);
background-color: rgba(107, 105, 105, 0);
transition: background-color 1s ease;
transition: color 1s ease;
overflow: hidden;
}
.image:hover .overlay {
background-color: rgba(107, 105, 105, 0.5);
color: rgba(255, 255, 255, 1);
transition: background-color 1s ease;
}
.textAnim {
animation: textAnimation 1s;
animation-play-state: paused;
position: relative;
padding-left: 50%;
top: 50%;
}
.image:hover .textAnim {
animation-play-state: running;
}
@keyframes textAnimation {
0% {
opacity: 0;
padding-top: 50%;
}
100% {
opacity: 1;
padding-top: 0%;
}
}
<section class="images">
<div class="container-3">
<div class="image">
<img src="http://via.placeholder.com/1000">
<div class="overlay">
<span class="textAnim" id="animation">
Lorem, ipsum dolor sit amet consectetur adipisicing elit. Dolorum, enim?
</span>
</div>
</div>
<div class="image">
<img src="http://via.placeholder.com/1000">
<div class="overlay">
<span class="textAnim" id="animaiton">
Lorem, ipsum dolor sit amet consectetur adipisicing elit. Dolorum, enim?
</span>
</div>
</div>
<div class="image">
<img src="http://via.placeholder.com/1000">
<div class="overlay">
<span class="textAnim" id="animation">
Lorem, ipsum dolor sit amet consectetur adipisicing elit. Dolorum, enim?
</span>
</div>
</div>
<div class="image">
<img src="http://via.placeholder.com/1000">
<div class="overlay">
<span class="textAnim" id="animation">
Lorem, ipsum dolor sit amet consectetur adipisicing elit. Dolorum, enim?
</span>
</div>
</div>
</div>
</section>