Jump to content

Search In
  • More options...
Find results that contain...
Find results in...

Request help for an animation using Intersection Observer

Recommended Posts


I have a basic animation for 3 items. It is from a section of a site I am building so I cleaned it up just to show the essentials. The 3 sections all animate once they are in the viewport. It is working but I really feel like there might be an easier way to set this up with less code. If this is the best option then I will go with it. But if anyone sees anything that can be improved (either with less code and/or better performance) please let me know. 

Also a huge thanks to the posts in this thread: 


I was having problems getting the animation's basic functionality working and used the ideas in this thread to get it working.

Thanks in advance for any assistance with improving this animation.

See the Pen gObGOvR by JasonDuquain (@JasonDuquain) on CodePen

Link to comment
Share on other sites

Hey Jason and welcome. 


Your setup is pretty good! Thanks for the minimal demo. The only thing I'd do differently is make the code more DRY (don't repeat yourself) by creating the tweens inside of the forEach. Then you can refer to that tween inside of the Intersection Observer and reduce code there as well:

See the Pen Exawjrd?editors=0010 by GreenSock (@GreenSock) on CodePen


P.S. You don't need quotes around the value for the y.

  • Like 4
Link to comment
Share on other sites

Very nice! Thank you for the quick help and making the code much cleaner!


I will update the code in my current project and make sure to add this to my gsap notes for future reference.



  • Like 2
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.