Jump to content
Search Community

toggleClass not working (with toggleActions)

amitr95 test
Moderator Tag

Recommended Posts

I'm trying to add a class on scroll to make the header fixed. However, the class isn't being applied?

 

I've seen existing posts on this, all which go about the same / similar way I have applied the snippet in my demo, but it doesn't work in my use case?

 

 

See the Pen bGjRjzp by amit_rai95 (@amit_rai95) on CodePen

Link to comment
Share on other sites

That's because of this: 

end: "+=1"

That means it toggled the class but if you scrolled more than 1 pixel past the start, it toggled it back again. Your entire ScrollTrigger only lasts 1 pixel. 

 

I assume you meant something more like this?:

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

 

But even that seems odd to me; why are you even toggling that class at all if it's gonna be on the entire time (start: 0, end: 99999)? Why not just apply that class directly and leave it there (no ScrollTrigger involvement)?

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