linear-gradient
works like background-image
, and how you can read here, background-image
is not animatable.
This is pretty obvious, because there's no a standard way to animate a background-image
. You could want to animate it with a fade-in effect or with a swipe-left effect, this is ambigous and I don't understand why you say it doesn't work "as expected". What was expected?
You should leverage on setting transition for other properties, like opacity
or width
.
This is an easy way to implement a fade effect on the background-image
property, using the ::after
pseudo-element:
.spotlight-next::after {
display: block;
content: "";
width: 100%;
height: 100%;
position: absolute;
right: 0;
top: 0;
transition: opacity 0.5s ease-out;
background: linear-gradient(90deg, rgba(0, 0, 0, 0), rgba(0, 0, 0, 1));
opacity: 0.1;
z-index: -1;
}
.spotlight-next:hover::after {
opacity: 1;
}
remove transition
and background-image
property from .spotlight-next
in order to make it work.