Is there a wheel end event or how to detect when user lift fingers from trackpad after wheel?
I'm want to achieve animations like macOS launchpad as the gif shown below, so I need to know when user lifted their fingers
CodePudding user response:
No, there's no such event and it's not possible to detect when the user has placed/removed their finger(s) on/from a trackpad.
- The
wheel
event fires when a physical mouse's wheel is rotated or a trackpad gesture is detected by the OS. - The various touch and pointer events fire for physical mouse movement, button presses, trackpad movement, and/or fingers on a touchscreen.
The basic thing to understand is that a trackpad emulates a traditional, physical mouse. The trackpad drivers convert touches into cursor movement, button clicks, and "wheel" movement. At least from the perspective of a web app, there's no way to tell whether the cursor movement is the result of a mouse or a trackpad.
In contrast, browsers make touch input on touchscreen devices available in detail to web apps, and you're able to override default behavior via preventDefault()
.
The best you'll be able to do is set a timeout after the last wheel
event. Reset your timeout after every wheel
event, and then fire your "end" event after the timeout expires. You may also want to "end" on mousemove
, since cursor movement probably means the user took the second finger off the trackpad and started moving one finger. Although keep in mind, a physical mouse can both move and wheel at the same time.