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

Bind MouseWheel to Horizontal Scroll #24

Closed
MrUltimate opened this issue Apr 17, 2022 · 3 comments
Closed

Bind MouseWheel to Horizontal Scroll #24

MrUltimate opened this issue Apr 17, 2022 · 3 comments

Comments

@MrUltimate
Copy link

Hello again,

I would be awesome to have the mousewheel bounding to the horizontal scroll as well. Is there a recommended approach when using scroll-motion?

Thanks!

@breadadams
Copy link
Owner

Hey @MrUltimate, horizontal scroll should be working already, since we take the page size from the body. In the storybook demo there's a "↔️ Horizontal" button at the top of the page that demonstrates this.

If you're experiencing problems please share a code sample/sandbox, and I'll check it this week 🙂

@MrUltimate
Copy link
Author

Thanks @breadadams, the horizontal scroll works just fine. On mac at least, you have to hold down shift while use the mousewheel to scroll, I was wondering if there's a recommended what to bind the vertical mousewheel scroll, to the horizontal scroll.

@breadadams
Copy link
Owner

breadadams commented Apr 21, 2022

Ah I see, I misunderstood your question.

You don't need to perform anything special with scroller-motion for this, a simple event listener on the window scroll that updates the body's scrollLeft with the "amount of scroll" would suffice. Something like this: https://stackblitz.com/edit/scroller-motion-forced-horizontal-scroll

useEffect(() => {
  // Based on https://stackoverflow.com/a/59680347/2553600
  const onWheel = (event) => {
    if (!event.deltaY) {
      return;
    }

    document.documentElement.scrollLeft += event.deltaY + event.deltaX;
  };

  window.addEventListener('wheel', onWheel);

  return () => window.removeEventListener('wheel', onWheel);
}, []);

breadadams added a commit that referenced this issue May 6, 2022
+ Add recipes for #22 and #24
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