Direct all scrolling to the x-axis #359
-
Not an issue, just a question. :) Version 8.0.0 Great library! What i'm trying to do: The start would be to use the "invertDelta" plugin to convert the axis. This already works great, when im scrolling up and down it scrolls the container left to right. But how to I combine this with the normal left to right behaviour? Like this example: The only way I thought of to get it to work ( solution could be very wrong ) is to check if if the direction is horizontal / verical in the invertDeltaPlugin: |
Beta Was this translation helpful? Give feedback.
Replies: 8 comments
-
What's the expected behavior when you scroll up-down with a trackpad? Edit: to be more explicitly, how will it behave when you get both |
Beta Was this translation helpful? Give feedback.
-
Thanks for your response. :) I think its about user intent which presents these cases:
In this layout you would like the site to scroll horizontal which ever the intent of the user.
|
Beta Was this translation helpful? Give feedback.
-
Not sure if it's a good solution, but I think you can simply keep the bigger delta value: transformDelta({x, y}) {
return {
y: 0,
x: Math.abs(x) > Math.abs(y) ? x : y,
};
} |
Beta Was this translation helpful? Give feedback.
-
Or maybe you can try the norm of vector transformDelta({x, y}) {
return {
y: 0,
x: Math.sign(x || y /* in case deltaX = 0 */) * Math.sqrt(x*x + y*y),
};
} Edit: |
Beta Was this translation helpful? Give feedback.
-
An important point is that we are likely to get both Personally, I prefer using the norm of vector Edit: the first solution behaves better in the demo 🙃 https://codepen.io/idiotWu/pen/KJNYye?editors=0010 Code: import Scrollbar, { ScrollbarPlugin } from 'smooth-scrollbar';
class HorizontalScrollPlugin extends ScrollbarPlugin {
static pluginName = 'horizontalScroll';
transformDelta(delta, fromEvent) {
if (!/wheel/.test(fromEvent.type)) {
return delta;
}
const { x, y } = delta;
return {
y: 0,
x: Math.abs(x) > Math.abs(y) ? x : y,
};
}
}
Scrollbar.use(HorizontalScrollPlugin); |
Beta Was this translation helpful? Give feedback.
-
I think this should be implemented as a plugin or a feature. it has a lot of use-cases |
Beta Was this translation helpful? Give feedback.
-
Hey, I m really struggling to use this plugin with react-smooth-scrollbar, any solution would come to mind? |
Beta Was this translation helpful? Give feedback.
-
It depends what you are trying to do? This solution works fine in most cases. |
Beta Was this translation helpful? Give feedback.
An important point is that we are likely to get both
deltaX
anddeltaY
while using trackpads (even you don't intend to), soy = 0
barely happens.Personally, I prefer using the norm of vector
(x, y)
(as commented above).Edit: the first solution behaves better in the demo 🙃 https://codepen.io/idiotWu/pen/KJNYye?editors=0010
Code: