Jump to content
GreenSock

Murugan S

jQuery Smooth Scroll doesn't work with ScrollTrigger

Go to solution Solved by GreenSock,

Recommended Posts

I have added jquery smooth scroll to next section from top to Scroll Down link. The scrolltrigger animation doesnt work properly. Could anyone please help me with this issues. Thank you

See the Pen WNEgeKW by murugans02 (@murugans02) on CodePen

Link to comment
Share on other sites

Welcome to the forums, @Murugan S. jQuery Smooth Scroll and smooth-scrollbar are not GreenSock products, so we can't really support them here  but the problem in your demo is that you're using jQuery Smooth Scroll to animate the "real" scroll position of the page, but you're using smooth-scrollbar to do scroll-jacking (fake scroll), and wiring that to ScrollTrigger so they're not synchronized at all. In other words, jQuery Smooth Scroll is scrolling the WRONG thing. Plus I think your offset that you're calculating is likely incorrect as well because again, it's based on positioning of the "real" scroll whereas you're doing fake-scroll stuff.

 

I would strongly recommend NOT using jQuery, much less jQuery Smooth Scroll. If your goal is to animate the scroll position, you can use GSAP's ScrollToPlugin, sorta like:

gsap.to(bodyScrollBar, {scrollTop: "+=" + $("#animatedsection").offset().top, duration: 1});

Good luck!

  • Like 1
  • Thanks 1
Link to comment
Share on other sites

Hi All, I need an help on the above, I need to add class to the body when the last section comes in viewport. Could you please help me on this. Thank you

Link to comment
Share on other sites

  • Solution

Based on the logic I see in your code...

ScrollTrigger.create({
  trigger: ".purple",
  start: () => "top -" + (window.innerHeight*(images.length-0.5)),
  scroller: ".scroller",
  onEnter: () => document.body.classList.add("your-class"),
  onLeaveBack: () => document.body.classList.remove("your-class")
});

 

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