Jump to content
GreenSock

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

Infinite rotation with getBoundingClientRect does not work

Warning: Please note

This thread was started before GSAP 3 was released. Some information, especially the syntax, may be out of date for GSAP 3. Please see the GSAP 3 migration guide and release notes for more information about how to update the code to GSAP 3's syntax. 

Recommended Posts

I am trying to make a rotation loop on my images only when they are in viewport. I want to pause this loop when they re out of the viewport. I am trying to use getClientBoundingRect to detect the position of my elements and I try to trigger the function when they are visible. The issue is that it only runs once. Console log is showing me that the viewport detection works fine, but the TweenMax.to animation is not working like it should. 

I do not want to use ext. libraries for viewport detection.

Any help is much than appreciated guys!

Thanks

See the Pen JjjbvvB by jurajmolnar (@jurajmolnar) on CodePen

Link to comment
Share on other sites

Hey @Juraj,

 

Welcome to the GreenSock Forum.

 

You could play() and pause(0) a timeline which is paused.
Here's an example with intersectionObserver

 

See the Pen GVpojX by mikeK (@mikeK) on CodePen

 

Happy tweening ...

Mikel

  • Like 4
Link to comment
Share on other sites

23 minutes ago, mikel said:

Hey @Juraj,

 

Welcome to the GreenSock Forum.

 

You could play() and pause(0) a timeline which is paused.
Here's an example with intersectionObserver

Happy tweening ...

Mikel

Thank you Mikel, this works just perfect. Have a great Sunday ;)  

  • Like 1
Link to comment
Share on other sites

@mikel i have one other little request. Imagine that i d like to use this animation on the page multiple times.

Your code works great for one. But every single time the object is in the viewport (no matter which one), it runs the animation for all of the objects on the page. Any idea of how to make this work only for the item visible in the viewport?

Many thanks man

Link to comment
Share on other sites

1 hour ago, Juraj said:

Any idea of how to make this work only for the item visible in the viewport?

You'd need to create a timeline for each element and have the target of the timeline animations be one specific element. I'd usually attach the timeline to the element itself so that inside of the Intersection Observer function you could say entry.target.action.play();

 

Here's an example pulled from another thread:

 

Link to comment
Share on other sites

6 minutes ago, mikel said:

With your code I have problems to use rootMargin or threshold.

Yes, I realized last evening that I mistakenly put the options in the .observe call instead of the Intersection Observer construction. I'll fix that now.

  • Like 1
Link to comment
Share on other sites

2 hours ago, mikel said:

@mikel you saved my day man. I was struggling with this badly.

 

 

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.
×