-
Hi 👋 I'm trying to create some sort of sliding carousel based on the If you onWheel over the blue elements, it goes from 0 to 2 and vice versa. I'd like to be able to make it do 0->1, 1->2, 2->1, 1->0 and so on. (kind of how netflix does it). If you have any idea how to accomplish this, I'd appreciate it. |
Beta Was this translation helpful? Give feedback.
Replies: 10 comments
-
Here's a rough implementation idea: https://codesandbox.io/s/onwheel-fire-once-5urx7 I suspect the difficulty here is a bit outside the scope of this lib, essentially it's about detecting user intention through wheel events which is not straightforward and might depend on user's hardware I suppose. Anyway, what's also tough with wheel is that wheel fires for a long time, and in your case you probably don't want to wait for wheel to come to rest, hence the idea in the sandbox to detect decelerating movement. I'd be curious if you've found another implementation somewhere to have a look at their code. Hope it helps anyway, was fun to try that out :D |
Beta Was this translation helpful? Give feedback.
-
Thank you for your help! You're right, I was initially trying to not get the wheel firing for so long by removing the event listener after the first event but I was hitting other issues and it didn't feel snappy enough. Thanks again, I'll keep doing some experiments and will post back here if I find anything interesting. |
Beta Was this translation helpful? Give feedback.
-
I’ll check Netflix’s page! |
Beta Was this translation helpful? Give feedback.
-
I believe they're using a similar implementation. I might be wrong, but it's not super snappy or reactive so I guess they're also swimming upstream against how wheel works. The sandbox above should do the work then, only I'm using vertical wheel instead of horizontal, but that's a pretty easy fix. |
Beta Was this translation helpful? Give feedback.
-
I think you're right. We're going against how the wheel is designed. I wonder if there is a way to not have it send so many events. Our current approach works if users don't wheel over a large distance, small distances make it more reactive. Anyway, thank you again for helping me with this! |
Beta Was this translation helpful? Give feedback.
-
@Magellol I'm using a combination of https://github.com/d4nyll/lethargy and a setTimeout() to do exactly this. Here's an example:
The problem I'm having is that Lethargy needs a new event after we trigger a 'switch'. Currently in order to do what I want I have to do it manually like this:
But obviously I'd rather use the onWheel Gesture event. |
Beta Was this translation helpful? Give feedback.
-
Hey @jwmann have a look at this sandbox and tell me how it works for you: You should be able to scroll through slides one by one using the vertical wheel. It's not as advanced as lethargy though, and I have only tested it on my MacBook trackpad and Magic Mouse. If you do want to use lethargy, here's a sandbox that I think reproduces lethargy's logic correctly. |
Beta Was this translation helpful? Give feedback.
-
@dbismut I appreciate the help. This is the entire reason why I'm using Lethargy. I appreciate you trying to make an example with Lethargy, however you're not quite using the LethargyJS library properly. Here's an updated version of your example:
Surprisingly, it seems to work well on all Platforms now. |
Beta Was this translation helpful? Give feedback.
-
Hm no, I'm not using last in that example, that I specifically built with inertia in mind and it works on my trackpad. It's very likely that Lethargy does a better job at this though.
Lethargy is just a way to distinguish real scroll events from inertia-triggered scroll events. You might use Lethargy so that you can only scroll one frame at a time (which seems to be your intent), but there's no improper use of Lethargy in the example above as far as I'm aware. There's nothing on Lethargy readme that implies using a timeout. Here's my last sandbox modified to use Lethargy. It doesn't involve using a timeout, it works just fine with my Macbook trackpad. |
Beta Was this translation helpful? Give feedback.
-
@dbismut Although I'm using a timeout, your new example still uses a reference to achieve the same result. That being said, I no longer have the original issue I described with the event. I think the only thing I changed was checking lethargy after making sure it was scrolling (aka So, thank you for helping me fix that! 😆 |
Beta Was this translation helpful? Give feedback.
@jwmann
Hm no, I'm not using last in that example, that I specifically built with inertia in mind and it works on my trackpad. It's very likely that Lethargy does a better job at this though.
Lethargy is just a way to distinguish real scroll events from inertia-triggered scroll events. You might use Lethargy so that you can only scroll one frame at a time (which seems to be your intent), but there's …