smooth-scrollbar
smooth-scrollbar copied to clipboard
.disableScroll() and .enableScroll() methods?
Hello again 😉,
Following the addition of the great delegateTo option, I’ve stumbled upon an interesting use case for a couple of useful methods that would allow us to “block” and “unblock” scrolling on a given Smooth Scrollbar instance.
Imagine you have a first Smooth Scrollbar on a whole page and choose to delegateTo the input events to the document because of fixed elements like a navigation bar, and you want to open up an overlay above said page. That overlay could have its own Smooth Scrollbar.
If you want to stop the scroll on the page beneath the overlay, you could stop the propagation of the events on the overlay (which Smooth Scrollbar already does if and instance is created on the overlay). However, if your layout requires the fixed navigation bar to still be above the overlay, then scrolling on it would cause the underlying page to scroll because of the delegateTo: document option. You’d have to manually stop/resume the propagation of events on the fixed elements, which can quickly become cumbersome depending on the amount of elements.
What do you think about a way to tell Smooth Scrollbar to temporarily pause its scroll? There might already be a way to do that, but I couldn’t find it in the docs.
Thanks!
You can do this with the plugin system. FYI: https://github.com/idiotWu/smooth-scrollbar/issues/119
Interesting, indeed! Thanks!
The .updatePluginOptions() method makes it fairly trivial to do.
Just for information though, do you think this is the kind of features you would consider adding to the core library in the future, or would you rather people implement it through the (admittedly great) plugin system?
IMO, I'd like to leave it to users because it's not an expected behavior of a scrollbar ;). What's more, if I add this method to the library, I'll have to set one more state like <bool>scrollbar.paused, which will increase the complexity of code and make it hard to maintain.
Well, overflow: hidden works for expected behaviour of a scrollbar. Would be great if we had similar option.