Jump to content
Search Community

className removing dynamically added classes

Jemes 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'm using the line below to add a scrolled class to an a nav element but when it's added it removes another dynamically added class from the nav.

.to($('nav'), 0.01, {css:{className:'+=scroll'}, ease: Linear.easeInOut })

Is there a way to only add the scrolled class and not remove the other class?

 

Thanks

 

Jemes

Link to comment
Share on other sites

 

hmmm, I could not replicate your claim. I found that existing class names were not removed as shown below.

 

Below you will see I add the className tall and the className red does not get removed.

 

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

 

 

Perhaps there is something specific to how you are dynamically adding the existing class, but I can't test that without a reduced test case.

 

Please fork the demo and modify it so that we can see what the issue is. The less code the better

 

thanks!

  • Like 2
Link to comment
Share on other sites

Hi,

 

Thanks for the reply.

So I have a click event on a burger element that adds an active class to the nav element.

  $('.burger').click(function(event){
    event.preventDefault();
    $('nav').toggleClass('active');
  });

 

When the active class is added the other tween using className removes active when actioned.

 

.to($('nav'), 0.01, {css:{className:'+=scroll'}, ease: Linear.easeInOut })

The tween above in only actioned once the page has been scrolled passed the header.

I hope helps?

 

Thanks

Jemes

Link to comment
Share on other sites

Please post a demo that clearly illustrates the issue. 

 

 

Unfortunately we don't have the resources (time) to repeatedly create demos in hopes that they replicate what you are doing.

 

Thanks for understanding.

 

 

 

 

  • Like 2
Link to comment
Share on other sites

Hello @Jemes
 

Any reason why your trying to animate a to() tween with a duration of 0.01 seconds. I don't see how a duration value that small can visually be animated. The duration value might as well be 0, did you mean to use a set() instead of a to().

 

But like @Carl advised a codepen demo example would be good if you would like us to assist you properly.

 

 

:)

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