aboutsummaryrefslogtreecommitdiff
path: root/files/zh-cn/web/api/element/dommousescroll_event/index.html
blob: a68a7be558128ed4ae0fbc62d80c2e47b02779cc (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
---
title: DOMMouseScroll
slug: Web/API/Element/DOMMouseScroll_event
translation_of: Web/API/Element/DOMMouseScroll_event
---
<p>{{ Non-standard_header() }}</p>

<p>The DOM <code>DOMMouseScroll</code> event is fired asynchronously when mouse wheel or similar device is operated and the accumulated scroll amount becomes over 1 line or 1 page since last event. It's represented by the {{ domxref("MouseScrollEvent") }} interface.</p>

<p>If you want to prevent the default action of mouse wheel events, it's not enough to handle only this event on Gecko because If scroll amount by a native mouse wheel event is less than 1 line (or less than 1 page when the system setting is by page scroll), other mouse wheel events may be fired without this event.<br>
 <br>
 On Gecko 17 (Firefox 17) or later, you need to call <code>preventDefault()</code> of <code>wheel</code> events which must be fired for every native event.<br>
 <br>
 On Gecko 16 or earlier, you need to call <code>preventDefault()</code> of <code>MozMousePixelScroll</code> event which must be fired for every native event.</p>

<p>Use standardized wheel event if available.</p>

<ul style="display: table; padding: 0; border-left: 2px solid; margin-left: 0.5em;">
 <li style="display: table-row; padding: 3px; margin: 0;"><dfn>Interface :</dfn>{{ domxref('MouseScrollEvent') }}</li>
 <li style="display: table-row; padding: 3px; margin: 0;"><dfn>Synchronicity :</dfn>asynchronous</li>
 <li style="display: table-row; padding: 3px; margin: 0;"><dfn>Bubbles :</dfn> yes</li>
 <li style="display: table-row; padding: 3px; margin: 0;"><dfn>Target :</dfn> {{ domxref("Element") }}, {{ domxref("Document") }}, {{ domxref("Window") }}</li>
 <li style="display: table-row; padding: 3px; margin: 0;"><dfn>Cancelable :</dfn> yes</li>
 <li style="display: table-row; padding: 3px; margin: 0;"><dfn>Default action :</dfn> Scroll, moving history, or zooming in/out</li>
</ul>

<h2 id="Properties">Properties</h2>

<p>The event has only one additional property beyond standard events.</p>

<h3 id="detail">detail</h3>

<p>The <code>detail</code> property describes the scroll more precisely, with positive values indicating scrolling downward and negative values indicating scrolling upward.</p>

<p>If the event represents scrolling up by a page, the value of <code>detail</code> is -32768. If the event indictes scrolling down by a page, the value is +32768. Any other value represents the number of lines to scroll, with the direction indicated by the value's sign.</p>

<div class="note">
<p><strong>Note:</strong> Trusted events are never sent with a value of 0 for <code>detail</code>.</p>
</div>

<p>Trusted events are never fired with 0.</p>

<div class="note">
<p><strong>Note</strong><strong>:</strong> If the platform's native mouse wheel events only provide scroll distance by pixels, or if the speed can be customized by the user, the value is computed using the line height of the nearest scrollable ancestor element of the event's target. If that element's font size is smaller than {{pref("mousewheel.min_line_scroll_amount")}}, that preference's value is used as the line height.</p>
</div>

<h2 id="Browser_compatibility">Browser compatibility</h2>

<p>{{ CompatibilityTable() }}</p>

<div id="compat-desktop">
<table class="compat-table">
 <tbody>
  <tr>
   <th>Feature</th>
   <th>Chrome</th>
   <th>Firefox (Gecko)</th>
   <th>Internet Explorer</th>
   <th>Opera</th>
   <th>Safari</th>
  </tr>
  <tr>
   <td>Basic support</td>
   <td>{{ CompatNo() }}</td>
   <td>{{ CompatGeckoDesktop("1.0") }}</td>
   <td>{{ CompatNo() }}</td>
   <td>{{ CompatNo() }}</td>
   <td>{{ CompatNo() }}</td>
  </tr>
 </tbody>
</table>
</div>

<div id="compat-mobile">
<table class="compat-table">
 <tbody>
  <tr>
   <th>Feature</th>
   <th>Android</th>
   <th>Firefox Mobile (Gecko)</th>
   <th>IE Mobile</th>
   <th>Opera Mobile</th>
   <th>Safari Mobile</th>
  </tr>
  <tr>
   <td>Basic support</td>
   <td>{{ CompatNo() }}</td>
   <td>{{ CompatGeckoMobile("1.0") }}</td>
   <td>{{ CompatNo() }}</td>
   <td>{{ CompatNo() }}</td>
   <td>{{ CompatNo() }}</td>
  </tr>
 </tbody>
</table>
</div>

<h2 id="See_also">See also</h2>

<ul>
 <li>{{ domxref("MouseScrollEvent") }}</li>
 <li>Gecko's legacy pixel scroll event: <code>MozMousePixelScroll</code></li>
 <li>Non-Gecko browsers' legacy mouse wheel event: <code>mousewheel</code></li>
 <li>Standardized wheel event: <code>wheel</code></li>
</ul>