Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Touchpad scroll detection in JS, no library

I'm making my own little Javascript library that makes it easy to replace the default scrollbars for your Website (and mine) with custom ones. Part of that means giving the BODY element an "overflow:hidden" style to hide the normal scrollbars. However, this prevents all scrolling except for that which is done in code.

I have everything working in terms of showing the bar and having it scroll when you click/drag it. However, many touchpads (like on the computer I'm testing this with) have a feature where you can scroll by sliding a finger along the right side of the pad. I need the library not to break that, so I need some way of detecting when the user tries to scroll this way.

I thought it would be interpreted by the browser as a mouse wheel, so I set up an onmousewheel event, but that doesn't seem to capture it at all. For the record, I'm testing with Firefox 25.0.1.

Is there any way to capture the trackpack scrolling, preferably without an external library? I'm trying to keep this as self-contained and lightweight as possible, but if I absolutely need to, I guess I can use jQuery and its mousewheel extension...

like image 961
Daniel Burnett Avatar asked Sep 15 '25 07:09

Daniel Burnett


1 Answers

Some browsers use the onwheel event instead of onmousewheel. So, it's usually a good idea to listen for both events.

See this MDN article for more about onwheel.

like image 164
Robbie Wxyz Avatar answered Sep 17 '25 22:09

Robbie Wxyz