I'm currently developing in React and facing a challenge where I need to trigger a fade animation for an element only when it becomes visible on the screen. The issue is that right now, the animation plays as soon as the page loads, which defeats the purpose if the user has to scroll to see it.
<Grid container className="AnimationContainer">
<img src="/images/animation1/circle.svg" className="Animation1-1" />
<img src="/images/animation1/calculator.svg" className="Animation1-2" />
</Grid>
In my CSS file, I've defined the styles:
.AnimationContainer {
place-content: center;
height: 200px;
width: 100%;
}
.Animation1-1 {
animation: fading 2s;
}
.Animation1-2 {
animation: fading 1.2s;
}
@keyframes fading{
0%{opacity:0}
100%{opacity:1}
}
Is there a way for me to ensure that the animation is triggered only when the Grid with class "AnimationContainer" or the images with classes "Animation1-1"/"Animation1-2" are within the visible portion of the screen?