Jump to content
GreenSock

Sukru

ToggleClass Button

Go to solution Solved by Rodrigo,

Recommended Posts

Hello, I want to close the content that I opened with the Menu button with the same button.

I use scroll pause when opening the menu, but to cancel it "smoother.paused(false);" I have to use is there a method like toggleclass for this?

Can you help me?

 

The code i use;


 

$(".hamburgerMenuOpen").click(function () {
    smoother.paused(true);
    $(".menu").addClass("visible");
  });

  //Hamburger Menu Close
  $(".hamburgerMenuClose").click(function () {
    smoother.paused(false);
    $(".menu").removeClass("visible");
  });

 

See the Pen poKybZq by sukruemanet (@sukruemanet) on CodePen

Link to comment
Share on other sites

The click handler for closing is on the ".hamburgerMenuClose" which does not exist. Below uses ".toggleClass" instead of ".addClass". 
Hope this is helpful.

See the Pen YzvqWmQ?editors=1010 by tripti1410 (@tripti1410) on CodePen

  • Like 1
Link to comment
Share on other sites

@Trapti Thanks for the answer but "smoother.paused(false);" you cannot scroll upwards with this scroll-down lock. Try it and you will see the problem.

Link to comment
Share on other sites

  • Solution

Hi,

 

Based on @Trapti's codepen just create a boolean to pause/unpause the ScrollSmoother instance:

// Menu is closed by default so the Smoother shouldn't be paused
let isPaused = false;

$(".hamburgerMenuOpen").click(function () {
  isPaused = !isPaused;
  smoother.paused(isPaused);
  $(".menu").toggleClass("visible");
});

Happy Tweening!

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