I have this animation on a div. What I want is when the page loads, it should animate once. And when I hover over it, it should animate once again.
The animation works fine when it's just on hover or just on load. But when I try to have it both ways (like in my example) it does not work. Why doesn't it work?
I also tried instead of defining the animation again on hover just putting in animation-play-state: running but that did not work either. When I look at it in chrome dev tools and force hover on the box element, I can see that the selectors are there, but the animation does nothing.
What's also curious is when I set the animation in hover to infinite with animation: test 1s infinite; then it works. It just not works when I want it to run once.
@keyframes test {
0% {
transform: scale(1);
}
25% {
transform: scale(1.25);
}
80% {
transform: scale(0.85);
}
100% {
transform: scale(1);
}
}
.box {
width: 300px;
height: 300px;
background-color: black;
display: block;
animation: test 1s;
}
.box:hover {
animation: test 1s;
}
<div class="box"></div>