I'm working on GSAP and I have two elements on different pages that have the same class and I want to apply their animation using scrollTrigger when I reach the element. Is there a way I can do this with a function instead of giving them a specific class and repeating myself?
Here is my code:
HTML:
<div class="container"></div>
<div class="containe">
<img class="image" src="./card-1.png" alt="">
</div>
<div class="container">
<img class="image" src="./card-2.png" alt="">
</div>
CSS:
.container{
height: 100vh;
}
GSAP:
gsap.to('.image' ,{
x:500,
rotation:250,
duration:1,
opacity:1,
scrollTrigger:{
trigger:'.image',
start:'top center',
toggleActions:'restart none none none',
}
})