Jump to content
Search Community

can I add a 'toggleClass' function in a scrolltrigger when the scroll direction changes?

weddje test
Moderator Tag

Go to solution Solved by weddje,

Recommended Posts

On the animated header I'm trying to make it appear on scroll down instantly. Even when I'm scrolled down to the bottom of the page. Currently it appears only when scrolling almost to the top of the page. In the example code below I'm trying to have a toggleClass() when the scroll direction is changed. But it's not working. Some advice is much appriciated ;) 

 

example code:

var scrollUp = document.querySelector('.jwpnavbar--up');


ScrollTrigger.create({
  start: 'top -50',
  end: 99999,
  markers:true,
  toggleClass: {className: 'jwpnavbar--scrolled', targets: '.jwpnavbar'}
});

ScrollTrigger.create({
  start: 'top -300',
  end: 99999,
  toggleClass: {className: 'jwpnavbar--up', targets: '.jwpnavbar'},
  onUpdate: ({direction}) => {
    if (direction == -1) {
      scrollUp.toggle('.jwpnavbar--scrolled')
    }
  }
  
});

 

See the Pen BazvJwZ by weddje (@weddje) on CodePen

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