Jump to content
Search Community

how to activate a different class on scroll up or scroll down

CodeBoi test
Moderator Tag

Recommended Posts

i managed to toggle class when scrolling but when i am scrolling back up i wish to activate a different class

 

 gsap.timeline({
  scrollTrigger: {
    trigger: "#tesla-car",
    start: "center center",
    end: "+=900",
    toggleClass: "active"
  },
});

here is the code im currently using ^

but i want to toggle a different class  when i scroll back up (hopefully thats understandable 

Link to comment
Share on other sites

Hey CodeBoi. You should use ScrollTrigger's callback methods (like onEnter, onLeave, onEnterBack, and onLeaveBack) to do more custom logic like this.

 

With that being said it might make more sense to just do what you need to do with an animation attached to your element(s) instead of toggling classes. Without seeing a minimal demo it's hard for us to give finite advice :) 

Link to comment
Share on other sites

3 hours ago, ZachSaucier said:

Hey CodeBoi. You should use ScrollTrigger's callback methods (like onEnter, onLeave, onEnterBack, and onLeaveBack) to do more custom logic like this.

 

With that being said it might make more sense to just do what you need to do with an animation attached to your element(s) instead of toggling classes. Without seeing a minimal demo it's hard for us to give finite advice :) 

wont lie had trouble yesterday adding tween but i finally managed to do it  (for those wondering why i used animations instead of gsap in the first place was due to an issue of the svg rotating out of place i fixed that by adding " transformOrigin: 50% 50% " to the gsap animation) now im using tween 

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