Looking at MDN's polyfil for the DOM3 wheel event, I found this line:
event.deltaY = - 1/40 * originalEvent.wheelDelta;
In the polyfil the event object for browsers not supporting dom3 event (wheel) is given a deltaY.
How is this proportion 1/40 * wheelDelta calculated? Why 1/40?
If I would create a similar polyfil for my library and would like to pass to event object the delta info, should I add both deltaX and deltaZ also? do the same proportions apply?
Why 1/40?
Microsoft used the legacy and non-standard MouseWheelEvent.
That event has a wheelDelta property, which is (source)
an abstract value which indicates how far the wheel turned.
On IE, that value is usually ±120 (source)
The value is the same as the delta value of
WM_MOUSEWHEELorWM_MOUSEHWHEEL. It means that if the mouse wheel doesn't support high resolution scroll, the value is 120 per notch. The value isn't changed even if the scroll amount of system settings is page scroll.
The polyfill uses a deltaMode of 1. That means that (source)
The delta values are specified in lines.
The default number of lines scrolled at a time is 3 (at least on Windows). You can change this number in Control Panel -> Mouse -> Wheel tab.
Then, 3 / 120 gives that 1 / 40 factor.
Do the same proportions apply to other axis?
Well, the problem is that (source)
IE and Opera (Presto) only support
wheelDeltaattribute and do not support horizontal scroll.
Therefore, the polyfill sets deltaX and deltaZ to 0.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With