Jump to content
Search Community

I want multiple add/remove active class in GSAP Timeline for Scrub animation.

NaimeshRao test
Moderator Tag

Recommended Posts

Hi There,

Is there any way to add multiple active class in different duration in gsap timeline?

Because I have one JS function which will run on that particular active class for limited duration.

 

I want multiple add/remove class in GSAP Timeline for Scrub animation.

 

Quote
gsap.timeline({
scrollTrigger: {
trigger: ".WMU_Container",
start: "top 30%",
end: "+=1000",
// markers: true,
pin: true,
pinSpacing: true,
scrub: 1,
defaults: {
ease: "Expo.easeOut",
duration: 1,
transformOrigin: "0 0",
},
},
})
 
/* WMU_Item 1 */
.from(".WMU_Container h2 .WrapLine", BottomTopOpt_SM)
.from(".WMU_Container .Make_Bar", LineExpand, "-= 0.05")
.from(".WMU_Container .WMU_Item1", { y: 20, opacity: 0 }, "> 0.3")
.to(".WMU_Container .WMU_Item1", { duration: 1.5 }, "> 0.3")
 
/* WMU_Item 2 */
.to(".WMU_Container .WMU_Item1", { y: 20, opacity: 0 })
.to(".WMU_Container .WMU1_txt", { y: 20, opacity: 0 }, "> 0.3")
.from(".WMU_Container .WMU_Item2", { y: 20, opacity: 0 })
.from(".WMU_Container .WMU2_txt", { y: 20, opacity: 0 }, "<")
.to(".WMU_Container .WMU_Item2", { duration: 1.5 })
 
/* WMU_Item 3 */
.to(".WMU_Container .WMU_Item2", { y: 20, opacity: 0 })
.to(".WMU_Container .WMU2_txt", { y: 20, opacity: 0 }, "> 0.3")
.from(".WMU_Container .WMU_Item3", { y: 20, opacity: 0 })
.from(".WMU_Container .WMU3_txt", { y: 20, opacity: 0 }, "<")
.to(".WMU_Container .WMU_Item3", {
duration: 3.5,
});

As above code, I want active class for  WMU_Item 1 / WMU_Item 2 / WMU_Item 3 when they are active and animating.
Is there any way to do it...
 

Thanks in advance!

Link to comment
Share on other sites

  • NaimeshRao changed the title to I want multiple add/remove active class in GSAP Timeline for Scrub animation.

It's pretty tough to troubleshoot without a minimal demo -  would you please provide a very simple CodePen or CodeSandbox that demonstrates the issue? 

 

Please don't include your whole project. Just some colored <div> elements and the GSAP code is best (avoid frameworks if possible). See if you can recreate the issue with as few dependancies as possible. If not, incrementally add code bit by bit until it breaks. Usually people solve their own issues during this process! If not, then at least we have a reduced test case which greatly increases your chances of getting a relevant answer.

 

Here's a starter CodePen that loads all the plugins. Just click "fork" at the bottom right and make your minimal demo

See the Pen aYYOdN by GreenSock (@GreenSock) on CodePen

 

If you're using something like React/Next/Nuxt/Gatsby or some other framework, you may find CodeSandbox easier to use. 

 

Once we see an isolated demo, we'll do our best to jump in and help with your GSAP-specific questions. 

 

A simplistic way of adding/removing a class would be to use an onStart and onComplete on the tween(s) to do that, but if you want it to be bulletproof running backwards or jumping the playhead around anywhere, you'd need to use an onUpdate or a custom plugin for that. I'm curious why you want to add/remove a class, though, instead of just using GSAP to set whatever properties you want. 

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