I am trying to build an animation that uncovers an image from right to left. However it doesn’t seem to be working the way I expected, it is currently going from left to right even after I changed "linear-gradient(to right" to "linear-gradient(to left". Is there a method that would be better suited for this or am I just missing something?
this is my code.
<div class="fade-in-img-2">
<img class="fade-img-2" src="url"/>
</div>
<style>
.fade-in-img-2 {
animation: left-to-right-fade-in-2 1s ease-in;
-webkit-mask-repeat: no-repeat;
display: flex;
justify-content: center;
}
.fade-in-img-2 .fade-img-2 {
width: 60%;
}
@keyframes left-to-right-fade-in-2 {
0% {
-webkit-mask-size: 0%;
-webkit-mask-image: linear-gradient(
to right,
rgba(0, 0, 0, 1) 70%,
rgba(0, 0, 0, 0)
);
}
100% {
-webkit-mask-size: 100%;
-webkit-mask-image: linear-gradient(
to right,
rgba(0, 0, 0, 1) 70%,
rgba(0, 0, 0, 0)
);
}
}
</style>
I changed "linear-gradient(to right" to "linear-gradient(to left" and expected the animation to be reversed however the animation ran in the same direction and did not seem to do anything.
2
Answers
in your
.fade-in-img-2
the animation needs to beanimation: right-to-left-fade-in-2 1s ease-in
and your keyframes:
To reverse your animation, you need to change the direction of the linear gradient in your keyframes. If you initially had "to right," you should change it to "to left" at 0% and 100% in your keyframes.
Here’s the modified code: