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?
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?
Share Improve this question edited Apr 5, 2018 at 12:37 iplus26 2,64717 silver badges26 bronze badges asked Jun 18, 2014 at 5:59 RikardRikard 7,80513 gold badges60 silver badges99 bronze badges1 Answer
Reset to default 7Why 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_MOUSEWHEEL
orWM_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
wheelDelta
attribute and do not support horizontal scroll.
Therefore, the polyfill sets deltaX
and deltaZ
to 0
.
发布者:admin,转转请注明出处:http://www.yc00.com/questions/1744176041a4561759.html
评论列表(0条)