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

Add onWheel callback for swap axes #46

Merged
merged 1 commit into from
May 24, 2020
Merged

Add onWheel callback for swap axes #46

merged 1 commit into from
May 24, 2020

Conversation

bragovo
Copy link
Contributor

@bragovo bragovo commented May 7, 2020

To create behaviour like on this site https://canals-amsterdam.nl/ (mouse wheel vertical but scroll by Y axis), I need add deltaY to scrollOffset.x
This advise #19 didn't help me, because position.x always 0.

Instead of adding an option for this, I created callback function on wheel event. So in my code i can replace it like this:

SBRef.current = new ScrollBooster({
  viewport: rootRef.current,
  content: contentRef.current,
  direction: 'horizontal',
  emulateScroll: true,
  scrollMode: 'native',
  onWheel: (state, event) => {
    SBRef.current.scrollOffset.x = -event.deltaY
  }
})

I'm not sure about how to set offset, like example above or:

...
this.props.onWheel(state, event, this);
...
onWheel: (state, event, object) => {
  object.scrollOffset.x = -event.deltaY
}

I don't see problems in PR approach.

@bragovo
Copy link
Contributor Author

bragovo commented May 7, 2020

Example for apple mouse, working this hoz and ver scroll

        onWheel: (state, event) => {
          let offsetX = 0
          if (event.deltaY >= 0 && event.deltaX >= 0) offsetX = Math.max(event.deltaY, event.deltaX)
          if (event.deltaY <= 0 && event.deltaX <= 0) offsetX = Math.min(event.deltaY, event.deltaX)
          SBRef.current.scrollOffset.x = -offsetX
          SBRef.current.scrollOffset.y = -event.deltaY
        }

@@ -480,6 +483,8 @@ export default class ScrollBooster {
this.scrollOffset.x = -event.deltaX;
this.scrollOffset.y = -event.deltaY;

this.props.onWheel(state, event);
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe move it to start of the function, before condition, so it can be used without emulateScroll option?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure, but in this case my modifications this.scrollOffset will be override by default, correct? Callback function must be after:

            this.scrollOffset.x = -event.deltaX;
            this.scrollOffset.y = -event.deltaY;

or it will be useless.

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh you right, thanks :) Merging it then

@ilyashubin ilyashubin merged commit 94c602c into ilyashubin:master May 24, 2020
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

Successfully merging this pull request may close these issues.

2 participants