Jump to content
GreenSock

Marnau

Disabling Observer on Vertical Scroll

Recommended Posts

Hi, I'm new to the forums and I created this codepen to show what I'm trying to achieve:

 

 

I used some of the code from Cassie's introduction to Observer to make this sections that move when we scroll down and up (.swipe-section). But when we get to the middle section (.scroll), I would like Observer to disable and allow for normal vertical scrolling. And in the last two sections it should go back to Observer action. I hope I made myself clear.

 

I don't know how I should go about disabling and re-enabling Observer properly. And I'm also having trouble because I have to make the middle section position:relative but then the scrollbar starts progressing at the beginning of the page.

 

I hope someone can point me in the correct direction. Thanks.

See the Pen PoewRRO by marnau (@marnau) on CodePen

Link to comment
Share on other sites

It sounds like you actually want to completely disable scroll for most of the sections and then in one, enable it. 

 

Personally, I think that's very unintuitive because the user sees a scrollbar but it doesn't move even though they're "scrolling" with their mouse wheel and seeing results...and then on some parts the scrollbar does actually work. 

 

But to answer your question, you'd have to call set preventDefault: true on the Observer if you want it to actually prevent scrolling while enabled. Then you'd sense when you're in the section that should scroll and disable() the Observer during that. Then when it reaches the end of that section, you'd have to enable() the Observer again. 

 

This demo might help a bit (it's from a different thread😞

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

Link to comment
Share on other sites

Thanks for your help, Jack. And you are right, it is an unnecessarily unintuitive solution.

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