Jump to content
GreenSock

Caroline_Portugal

Reposition animation on screen resize

Go to solution Solved by PointC,

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

Hey guys, 

 

In this pen I have 4 elements that are animated diagonally around the screen. On resize I'd like the elements' position to be reset. I tried to do that on line 35, but it isn't working. 

 

Any suggestions on how I might achieve this?  

 

Thank you so much for your help, 

 

Caroline

 

(GSAP's code is from line 1-63)

See the Pen yJGVWm?editors=1010#0 by carolineportugal (@carolineportugal) on CodePen

  • Like 1
Link to comment
Share on other sites

For performance purposes tweens record their starting and ending values. The best thing to do is to create new tweens on resize like:

 

http://codepen.io/GreenSock/pen/ZOVJqR?editors=0010

 

Notice I'm using x and y instead of top and left as css transforms are known to perform better.

  • Like 2
Link to comment
Share on other sites

Hey Carl, 

 

Thanks so much for getting back to me. I have spent quite some time on this but still not getting what I want (I am sorry, I am poorly alphabetized in JS). I have tweaked your pen to show you what I'm trying to do. It's basically a timeline with an object moving after the other object is finished moving. This works fine until the screen is resized. 

 

After a few screen resizes it all gets buggy, with objects moving at various times, not when the other is finished. Not sure what else to try.

 

Thanks so much again for your help, 

 

See the Pen LkraEx?editors=0010 by carolineportugal (@carolineportugal) on CodePen

Link to comment
Share on other sites

  • Solution

Hi Caroline_Portugal :)

 

I think the simplest thing here would be to kill() the old timeline and create a new one on your window resize event. Here's a fork of your fork of Carl's pen. 

 

See the Pen zBybXz by PointC (@PointC) on CodePen

 

Hopefully that helps a bit.

 

Happy tweening.

:)

  • Like 3
Link to comment
Share on other sites

Point C, this is perfect now!

 

I hadn't thought there were basically two timelines going on at the same time...

 

Thanks so much!

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