I have a flexbox with 4 images, when hovered on one of the images an animation plays, but when i hover again the animation is no longer playing.
From what i've read so far i have to restart the animation using JavaScript, but the solutions i found on the web are not working for me.
Should i target span by ID and add/remove "textAnim" class in JS? How to do it when i hover 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>