Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Issue when using jquery.Waypoints #304

Closed
c9mb opened this issue Feb 28, 2021 · 9 comments
Closed

Issue when using jquery.Waypoints #304

c9mb opened this issue Feb 28, 2021 · 9 comments

Comments

@c9mb
Copy link

c9mb commented Feb 28, 2021

I have a site that uses jquery.Waypoints to initiate animation when page elements scroll into the viewport.

When I add OverlayScrollbars to the body element (on dom load) this appears to interfere/block the scroll-events triggering the waypoint activation - and so no animations are shown.

If I disable OverlayScrollbars, then jquery.Waypoints behaves as expected, and the page animations are activated when the elements scroll into view.

@c9mb
Copy link
Author

c9mb commented Mar 2, 2021

Actually, the problem appears to be wider than just the plugin, and extends to general use of jquery.scroll() event, which this plugin also uses. I have other code relying on the jquery scroll() event handler, and it doesn't function when overlayscrollbars is active.

@KingSora
Copy link
Owner

KingSora commented Mar 2, 2021

Good day @c9mbundy!

Please create a minimal example on JSFiddle, CodeSandbox or StackBlitz. I really appreciate your detailed description, but without a example its very hard to figure out the problem.

@c9mb
Copy link
Author

c9mb commented Mar 2, 2021

Ok, I'll try to find some time to do that, and see if I can repro in a simple example.

As you might imagine, my working application is quite complex, but the gist of the problem is that scroll events are not making it past overlayScrollbars for reasons I don't understand (likely stupidity on my part).

$('body').overlayScrollbars({ overflowBehavior: { x: "hidden" }, scrollbars: { autoHide: "move" }, callbacks: { onScroll: function (e) { console.log('Overlay: ', e); } } });
$(window).scroll(function (e) { console.log('Native-Window: ', e); })

No console output from $(window).scroll() - which explains why my other $(window).scroll() callbacks are not working.

But if I comment it out...

//$('body').overlayScrollbars({ overflowBehavior: { x: "hidden" }, scrollbars: { autoHide: "move" }, callbacks: { onScroll: function (e) { console.log('Overlay: ', e); } } });
$(window).scroll(function (e) { console.log('Native-Window: ', e); })

Then I get output from $(window).scroll() and everything starts working again.

@KingSora
Copy link
Owner

KingSora commented Mar 2, 2021

@c9mbundy that happens because OverlayScrollbars is generating its own DOM, and therefore the scroll event isn't actually happening anymore directly on the body element, but on a different element instead. This is something I plan to change in v2.0.0 of the plugin.

@c9mb
Copy link
Author

c9mb commented Mar 2, 2021

I see - I seem to recall that scroll events don't bubble-up - so I assume that's why the document and window scroll events don't fire, as scrolling the entire page seems to be a special case that fires those.
I use window scroll events all the time, so I guess that's a show-stopper for me with the current version.
I'm pretty sure that WayPoints is using scroll events and also making the assumption of 'window' being the default element receiving scroll events for the entire page, so that perhaps explains it too.

@KingSora
Copy link
Owner

KingSora commented Mar 3, 2021

@c9mbundy yes, thats usually how such libraries work. Sometimes they provide a option where you can specify the viewport, then you could specify there the new element create by OverlayScrollbars. In jQuery Waypoints its the context option: http://imakewebthings.com/waypoints/api/context-option/

I've created a small example for you: https://jsfiddle.net/4akzm0fc/ maybe this helps :)

@c9mb
Copy link
Author

c9mb commented Mar 14, 2021

Sorry for the delayed reply - I've been tied up on a project - rent to pay and all that,

Changes to Waypoints are helpful, thanks, but unfortunately doesn't address the primary issue of not being able to rely on Window/Document scroll events when OverlayScrollbars is applied to the body. I have existing code depending on Window/Document scroll events when the body scrolls, and I'm not sure how to work around that with this version.

@KingSora
Copy link
Owner

@c9mbundy Unfortunately you'll need to wait until the release of v2.0.0. I can't address this issue in v.1 because its definitely a breaking change.

@KingSora
Copy link
Owner

v2 released today where this issue should be fixed :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants