To create this effect, utilize CSS keyframe animations.
Here's an outline to follow:
@keyframes greyscale-fade-in {
0% { -webkit-filter: grayscale(100%); }
100% { -webkit-filter: grayscale(0%); }
}
.image-selector {
animation: greyscale-fade-in 1s ease-in forwards;
}
The keyframes dictate how the image should be altered as the page loads.
You need to specify which keyframes to apply (greyscale-fade-in
), the duration of the animation (1s
means 1 second), and the type of transition (ease-in
).
By using the forwards
parameter, the animation only progresses from 0% to 100% and does not reverse from 100% to 0%.
Make sure to target your image by applying the animation rule to a selector that either selects your <img>
or its container <div>
.
For a comprehensive guide on animations, refer to: https://developer.mozilla.org/en-US/docs/Web/CSS/animation