Jump to content
Search Community

Using a function to animate and passing parameters

Jo Mourad test
Moderator Tag

Recommended Posts

I've searched around, but can't find what i need. Maybe because i don't know what terms to search for... (LEARNING CODING AS I GO...)

 

Basically, i have an animation that i want to call in several pages. But i want, let's say, to change the duration of that animation for some instances. Or maybe the "x" translation.

 

So i created a function for my animation

function fuzionAnim() {
    gsap.to(".fuzion", 10, {x:100, yoyo:true, repeat:-1, ease:"none"})
}

and call it in the specified pages 

fuzionAnim(); 

But can i pass a parameter to the function? For example

fuzionAnim(8); // 8 being the duration i want

How would i do that?

 

i know it's probably plain javascript fundamentals, but i need a bit of help!

Thanks!

Link to comment
Share on other sites

Heya! No worries, we love nice simple well explained questions in here!

You could do something like this

function fuzionAnim(myDuration) {
    gsap.to(".fuzion", {x:100, yoyo:true, repeat:-1, duration: myDuration, ease:"none"})
}

fuzionAnim(2)


But...

GSAP has an official way to do exactly what you're creating, so take a look at registerEffect too!

https://greensock.com/docs/v3/GSAP/gsap.registerEffect()

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