I have div
that has an animation in :hover
, but if the user takes the mouse from above div
before the animation finishes it cuts in half and does not finish.
I tried to do a spot light effect that crosses the image from left to right on the :hover
mouse, but if the mouse leaves the animation it stops abruptly. I would like this spot light to continue traversing the image to the end even if the mouse exits from above div
.
See the problem occurring when you do :hover
and then remove the mouse shortly after spot to traverse the image completely.
html, body {
width: 100%;
height: 100%;
margin: 0;
padding: 0;
}
.box {
width: 50%;
height: 200px;
background-color: gray;
position: relative;
margin: 20px auto;
overflow: hidden;
background-image: url(http://placecage.com/700/300);
background-repeat: no-repeat;
background-position: center;
background-size: 100% 100%;
}
.box:hover::after,
.box:hover::before {
content: "";
width: 40%;
height: 200px;
position: absolute;
z-index: 2;
background-image: linear-gradient(to right, rgba(255,255,255,0) 0%, rgba(255,255,255,0.8) 40%,rgba(255,255,255,0.8) 60%, rgba(255,255,255,0) 100%);
transform: skewX(-5deg);
left: -40%;
animation: bgc 1000ms linear forwards;
mix-blend-mode: overlay;
}
@keyframes bgc {
0% {left: -40%}
100% {left: 140%}
}
<div class="box"></div>
OBS: The animation only happens once every mouse over.