Jump to content
Search Community

Animate value halfway through onUpdate?

jesper.landberg test
Moderator Tag

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

Hi,

 

I have this piece of code:

 

      let gradient = { valA: 0, valB: 0 }

      elem.tl
        .from(elem.el, 1.25, {
          alpha: 0,
          ease: Linear.easeNone
        }, 0)
        .to(gradient, 0.75, {
          valA: 0,
          valB: 50,
          ease: Linear.easeNone,
          onUpdate: () => {
            TweenMax.set(elem.el, {
              webkitMaskSize: 'cover',
              webkitMaskImage: `linear-gradient(170deg, rgb(0, 0, 0) 0%, rgba(255, 255, 255, 0) ${gradient.valB}%)`,
            })                
          } 
        }, 0)
        .to(gradient, 0.5, {
          valA: 100,
          valB: 100,
          ease: Linear.easeNone,
          onUpdate: () => {
            TweenMax.set(elem.el, {
              webkitMaskSize: 'cover',
              webkitMaskImage: `linear-gradient(170deg, rgb(0, 0, 0) ${gradient.valA}%, rgba(255, 255, 255, 0) ${gradient.valB}%)`,
            })                
          } 
        }, 1) 

 

What I am doing here is that I update the gradient value onUpdate. But since I need valA to just be updated halfway through it looks like above.

 

Basically what I want is this:

 

`linear-gradient(170deg, rgb(0, 0, 0) ${gradient.valA}%, rgba(255, 255, 255, 0) ${gradient.valB}%)`

 

To be animated in this order:

gradient.valB animates from 0-100 during the full onUpdate sequence.

gradient.valA animates from 0-100 starting at the half mark of the onUpdate sequence.

 

Possible to do this in some more elegant way than two different onUpdate functions as above?

Link to comment
Share on other sites

Sure, all you need is one onUpdate. Here's some simplified code: 

let gradient = { valA: 0, valB: 0 }

elem.tl
.to(gradient, 1, {
  valB: 100,
  ease: Linear.easeNone,
  onUpdate: () => {
    TweenMax.set(elem.el, {
      webkitMaskSize: 'cover',
      webkitMaskImage: `linear-gradient(170deg, rgb(0, 0, 0) ${gradient.valA}%, rgba(255, 255, 255, 0) ${gradient.valB}%)`,
    })                
  } 
}, 0)
.to(gradient, 0.5, {
  valA: 100,
  ease: Linear.easeNone
}, "-=0.5"); 

 

You can have tweens update the raw "gradient.valA" and "gradient.valB" as much as you want, and just point their onUpdate to a common function if you'd rather - the point is simply to have that function apply ALL of the values to the final string.

 

Is that what you're looking for? 

 

 

  • Like 3
Link to comment
Share on other sites

4 minutes ago, GreenSock said:

Sure, all you need is one onUpdate. Here's some simplified code: 


let gradient = { valA: 0, valB: 0 }

elem.tl
.to(gradient, 1, {
  valB: 100,
  ease: Linear.easeNone,
  onUpdate: () => {
    TweenMax.set(elem.el, {
      webkitMaskSize: 'cover',
      webkitMaskImage: `linear-gradient(170deg, rgb(0, 0, 0) ${gradient.valA}%, rgba(255, 255, 255, 0) ${gradient.valB}%)`,
    })                
  } 
}, 0)
.to(gradient, 0.5, {
  valA: 100,
  ease: Linear.easeNone
}, "-=0.5"); 

 

You can have tweens update the raw "gradient.valA" and "gradient.valB" as much as you want, and just point their onUpdate to a common function if you'd rather - the point is simply to have that function apply ALL of the values to the final string.

 

Is that what you're looking for? 

 

 

 

Sure is:) Kind of obvious when I look at it! Thanks for the fast answer!

 

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