Jump to content
Search Community

Passing .to animations into a timeline as variables

PG1 test
Moderator Tag

Go to solution Solved by nico fonseca,

Recommended Posts

In this pen I have a timeline. It has 4 '.to' statements, representing two pairs providing different animations where the card on the right moves, then moves back to its starting point. 

As part of a wider project, I'd like to be able to pass in a movement, or one of these pairs, as a variable. What I'm trying looks a little like this:

const variable = ` <-- trying using backticks
.to(".card1", {
  x: "-60px",
  duration: 0.5,
  ease: "power4.inOut"
})
  .to(".card1", {
    x: "0px",
    duration: 1,
    ease: "power2.inOut"
  })`

tl
.variable <-- PASSING THIS IN DOESN'T WORK
.to(".card1", {
    rotation: "-45deg",
    duration: 0.2,
    ease: "power1.inOut"
  })
  .to(".card1", {
    rotation: "360deg",
    duration: 1,
    delay: 0.2,
    ease: "power1.inOut"
  });

I'm sure there's an easy solution here. 

I guess the next question i'll have is how you would pass in these variables conditionally... like can you embed a ternary into the chain?

Thanks!!
 

See the Pen f216578054531e1fcdef26b956520f03 by petegarvin1 (@petegarvin1) on CodePen

Link to comment
Share on other sites

On 8/26/2021 at 4:27 PM, nico fonseca said:

Hey @PG1 You can encapsulate timelines in functions and return them. So you can add them to your main timeline in case you need it.

 

 


Does this help you ? 🙂

 

 


 

Are you able to pass the delay in as a variable to the function that creates the timelines?

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