Jump to content
Search Community

How can I simplify this gsap code

HomTom test
Moderator Tag

Recommended Posts

What would be a shorter and better way to achieve the same animation?

For example would it be possible to use yoyo effect for it?

 

const myAnimation = gsap.timeline({ repeat: -1 });

myAnimation
.fromTo('.rectangle', {
  duration: 3,
  scale: 0,
  opacity: 0,
  rotate: -160
},
{
  duration: 3,
  scale: 1,
  opacity: 1,
  rotate: 0
})
.to('.rectangle', {
  duration: 3,
  scale: 2,
  opacity: 1,
  rotate: 160
}, '<=1')
.to('.rectangle', {
  duration: 3,
  scale: 0,
  opacity: 0,
  rotate: -160
})

 

 

 

See the Pen VwvjpGa?editors=1000 by itsthomas (@itsthomas) on CodePen

Link to comment
Share on other sites

2 hours ago, HomTom said:

1. You first set the scale to 2, why?

Because it uses a ‘from’ tween, so you set the end result and then tween it from 0. You could instead use a ‘to’ tween and adjust things as needed.

 

7 hours ago, HomTom said:

For example would it be possible to use yoyo effect for it?

Sure you could 'yoyo' using only one 'fromTo'.

 

const myAnimation = gsap.timeline({ repeat: -1, yoyo:true });
myAnimation
.fromTo('.rectangle', {
  duration: 3,
  scale: 0,
  opacity: 0,
  rotate: -160
},
{
  duration: 3,
  scale: 1,
  opacity: 1,
  rotate: 0
});
  • 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.
×
×
  • Create New...