Skip to content

Direct all scrolling to the x-axis #359

Answered by idiotWu
HeyHeyElske asked this question in FAQ
Discussion options

You must be logged in to vote

user scrolls to the side with trackpad ( we get x-value and y=0, dont invert delta )

An important point is that we are likely to get both deltaX and deltaY while using trackpads (even you don't intend to), so y = 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:

import Scrollbar, { ScrollbarPlugin } from 'smooth-scrollbar';

class HorizontalScrollPlugin extends ScrollbarPlugin {
  static pluginName = 'horizontalScroll';

  transformDelta(delta, fromEvent) {
    if (!/wheel/.test(fromEvent.type)) {
      return delta;
    }
        
    c…

Replies: 8 comments

Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Answer selected by idiotWu
Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
FAQ
Labels
plugin system FAQ Frequently Asked Questions
5 participants
Converted from issue

This discussion was converted from issue #181 on June 10, 2021 17:06.