aboutsummaryrefslogtreecommitdiff
path: root/files/ru/web/api/element/mouseleave_event/index.html
blob: 6f0e633b071958b6063f74a3618bb5a577f80ff2 (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
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
---
title: mouseleave
slug: Web/API/Element/mouseleave_event
translation_of: Web/API/Element/mouseleave_event
---
<div>{{APIRef}}</div>

<p class="summary">Событие <code>mouseleave</code> срабатывает, когда курсор манипулятора (обычно мыши) перемещается за границы элемента.</p>

<p><code>mouseleave</code> <code>и</code> {{event('mouseout')}} схожи, но отличаются тем, что <code>mouseleave</code> не всплывает, а <code>mouseout</code> всплывает.<br>
 Это значит, что <code>mouseleave</code> срабатывает, когда курсор выходит за границы элемента <em>и</em> всех его дочерних элементов, в то время как <code>mouseout</code> срабатывает, когда курсор покидает границы элемента <em>или</em> одного из его дочерних элементов (даже если курсор все ещё находится в пределах элемента).</p>

<table class="standard" style="border: solid 1px;">
 <tbody>
  <tr>
   <td><img alt="mouseenter.png" class="default internal" src="/@api/deki/files/5910/=mouseleave.png"></td>
   <td><img alt="mouseover.png" class="default internal" src="/@api/deki/files/5911/=mouseout.png"></td>
  </tr>
  <tr>
   <td>Одно <code>mouseleave</code> событие шлётся каждому элементу в иерархии в момент выхода курсора за их границы. Здесь 4 события рассылаются четырём элементам в иерархии когда курсор передвигается от текста к области за границей самого внешнего div элемента представленного на картинке.</td>
   <td>Одно единственное <code>mouseout</code> событие шлётся самому глубоколежащему элементу в DOM дереве, затем оно поднимается вверх по иерархии пока не будет отменено обработчиком или не достигнет корня.</td>
  </tr>
 </tbody>
</table>

<p> </p>

<h2 id="Общая_информация">Общая информация</h2>

<dl>
 <dt style="float: left; text-align: right; width: 120px;">Спецификация</dt>
 <dd style="margin: 0 0 0 120px;"><a class="external" href="https://www.w3.org/TR/DOM-Level-3-Events/#event-type-mouseleave">DOM L3</a></dd>
 <dt style="float: left; text-align: right; width: 120px;">Интерфейс</dt>
 <dd style="margin: 0 0 0 120px;">{{domxref('MouseEvent')}}</dd>
 <dt style="float: left; text-align: right; width: 120px;">Bubbles</dt>
 <dd style="margin: 0 0 0 120px;">Нет</dd>
 <dt style="float: left; text-align: right; width: 120px;">Отменяемое</dt>
 <dd style="margin: 0 0 0 120px;">Нет</dd>
 <dt style="float: left; text-align: right; width: 120px;">Цель</dt>
 <dd style="margin: 0 0 0 120px;">{{cssxref('Element')}}</dd>
 <dt style="float: left; text-align: right; width: 120px;">Действие по умолчанию</dt>
 <dd style="margin: 0 0 0 120px;">Нет</dd>
</dl>

<h2 id="Свойства">Свойства</h2>

<table class="standard-table">
 <thead>
  <tr>
   <th scope="col">Свойство</th>
   <th scope="col">Тип</th>
   <th scope="col">Описание</th>
  </tr>
 </thead>
 <tbody>
  <tr>
   <td><code>target</code> {{readonlyInline}}</td>
   <td>{{domxref("EventTarget")}}</td>
   <td>Целевой элемент события (вышележащий элемент в DOM дереве).</td>
  </tr>
  <tr>
   <td><code>type</code> {{readonlyInline}}</td>
   <td>{{domxref("DOMString")}}</td>
   <td>Тип события.</td>
  </tr>
  <tr>
   <td><code>bubbles</code> {{readonlyInline}}</td>
   <td>Boolean</td>
   <td>
    <p>Поднимается ли событие вверх как принято или нет</p>
   </td>
  </tr>
  <tr>
   <td><code>cancelable</code> {{readonlyInline}}</td>
   <td><code>Boolean</code></td>
   <td>Является ли событие отменяемым или нет?</td>
  </tr>
  <tr>
   <td><code>view</code> {{readonlyInline}}</td>
   <td>{{domxref("WindowProxy")}}</td>
   <td>{{domxref("document.defaultView")}} (<code>window</code> объекта document)</td>
  </tr>
  <tr>
   <td><code>detail</code> {{readonlyInline}}</td>
   <td><code>long</code> (<code>float</code>)</td>
   <td>0.</td>
  </tr>
  <tr>
   <td><code>currentTarget</code> {{readonlyInline}}</td>
   <td>{{domxref("EventTarget")}}</td>
   <td>Целевой узел (элемент), который используется обработчиком события.</td>
  </tr>
  <tr>
   <td><code>relatedTarget</code> {{readonlyInline}}</td>
   <td>{{domxref("EventTarget")}}</td>
   <td>Для <code>mouseover</code>, <code>mouseout</code>, <code>mouseenter</code> и <code>mouseleave</code> событий: цель дополнительного события (<code>mouseleave</code> цель в случае наступления <code>mouseenter</code> события). <code>null</code> иначе.</td>
  </tr>
  <tr>
   <td><code>screenX</code> {{readonlyInline}}</td>
   <td>long</td>
   <td>X координата указателя мыши в глобальных (относительно экрана) координатах.</td>
  </tr>
  <tr>
   <td><code>screenY</code> {{readonlyInline}}</td>
   <td>long</td>
   <td>Y координата указателя мыши в глобальных (относительно экрана) координатах.</td>
  </tr>
  <tr>
   <td><code>clientX</code> {{readonlyInline}}</td>
   <td>long</td>
   <td>X координата указателя мыши в локальных (относительно DOM содержимого) координатах.</td>
  </tr>
  <tr>
   <td><code>clientY</code> {{readonlyInline}}</td>
   <td>long</td>
   <td>Y координата указателя мыши в локальных (относительно DOM содержимого) координатах.</td>
  </tr>
  <tr>
   <td><code>button</code> {{readonlyInline}}</td>
   <td>unsigned short</td>
   <td>Всегда 0, так как нажатие любой кнопки не может произвести это событие (mouse movement does).</td>
  </tr>
  <tr>
   <td><code>buttons</code> {{readonlyInline}}</td>
   <td>unsigned short</td>
   <td>The buttons depressed when the mouse event was fired: Left button=1, Right button=2, Middle (wheel) button=4, 4th button (typically, "Browser Back" button)=8, 5th button (typically, "Browser Forward" button)=16. If two or more buttons are depressed, returns the logical sum of the values. E.g., if Left button and Right button are depressed, returns 3 (=1 | 2). <a href="/en-US/docs/Web/API/MouseEvent">More info</a>.</td>
  </tr>
  <tr>
   <td><code>mozPressure</code> {{readonlyInline}}</td>
   <td>float</td>
   <td>The amount of pressure applied to a touch or tabdevice when generating the event; this value ranges between 0.0 (minimum pressure) and 1.0 (maximum pressure).</td>
  </tr>
  <tr>
   <td><code>ctrlKey</code> {{readonlyInline}}</td>
   <td>boolean</td>
   <td><code>true</code> if the control key was down when the event was fired. <code>false</code> otherwise.</td>
  </tr>
  <tr>
   <td><code>shiftKey</code> {{readonlyInline}}</td>
   <td>boolean</td>
   <td><code>true</code> if the shift key was down when the event was fired. <code>false</code> otherwise.</td>
  </tr>
  <tr>
   <td><code>altKey</code> {{readonlyInline}}</td>
   <td>boolean</td>
   <td><code>true</code> if the alt key was down when the event was fired. <code>false</code> otherwise.</td>
  </tr>
  <tr>
   <td><code>metaKey</code> {{readonlyInline}}</td>
   <td>boolean</td>
   <td><code>true</code> if the meta key was down when the event was fired. <code>false</code> otherwise.</td>
  </tr>
 </tbody>
</table>

<h2 id="Примеры">Примеры</h2>

<p>The <a href="https://developer.mozilla.org/en-US/docs/Web/Events/mouseout#Example"><code>mouseout</code> </a>documentation has an example illustrating the difference between <code>mouseout</code> and <code>mouseleave</code>.</p>

<p>The following example illustrates how to use <code>mouseout</code>, to simulate the principle of event delegation for the mouseleave event.</p>

<pre class="brush: html">&lt;ul id="test"&gt;
  &lt;li&gt;
    &lt;ul class="leave-sensitive"&gt;
      &lt;li&gt;item 1-1&lt;/li&gt;
      &lt;li&gt;item 1-2&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;ul class="leave-sensitive"&gt;
      &lt;li&gt;item 2-1&lt;/li&gt;
      &lt;li&gt;item 2-2&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
&lt;/ul&gt;

&lt;script&gt;
  var delegationSelector = ".leave-sensitive";

  document.getElementById("test").addEventListener("mouseout", function( event ) {
    var target = event.target,
        related = event.relatedTarget,
        match;

    // search for a parent node matching the delegation selector
    while ( target &amp;&amp; target != document &amp;&amp; !( match = matches( target, delegationSelector ) ) ) {
        target = target.parentNode;
    }

    // exit if no matching node has been found
    if ( !match ) { return; }

    // loop through the parent of the related target to make sure that it's not a child of the target
    while ( related &amp;&amp; related != target &amp;&amp; related != document ) {
        related = related.parentNode;
    }

    // exit if this is the case
    if ( related == target ) { return; }

    // the "delegated mouseleave" handler can now be executed
    // change the color of the text
    target.style.color = "orange";
    // reset the color after a small amount of time
    setTimeout(function() {
        target.style.color = "";
    }, 500);


  }, false);


  // function used to check if a DOM element matches a given selector
  // the following code can be replaced by this IE8 compatible function: https://gist.github.com/2851541
  function matches( elem, selector ){
    // the matchesSelector is prefixed in most (if not all) browsers
    return elem.matchesSelector( selector );
  };
&lt;/script&gt;</pre>

<h2 id="Браузерная_совместимость">Браузерная совместимость</h2>

<p>{{CompatibilityTable}}</p>

<div id="compat-desktop">
<table class="compat-table">
 <tbody>
  <tr>
   <th>Feature</th>
   <th>Chrome</th>
   <th>Edge</th>
   <th>Firefox (Gecko)</th>
   <th>Internet Explorer</th>
   <th>Opera</th>
   <th>Safari</th>
  </tr>
  <tr>
   <td>Basic support</td>
   <td>30<sup>[1]</sup></td>
   <td>{{CompatVersionUnknown}}</td>
   <td>10<sup>[2]</sup></td>
   <td>5.5</td>
   <td>{{CompatVersionUnknown}}<br>
    {{CompatNo}} 15.0<br>
    17.0</td>
   <td>7<sup>[3]</sup></td>
  </tr>
  <tr>
   <td>On disabled form elements</td>
   <td>{{CompatNo}}</td>
   <td>{{CompatNo}}</td>
   <td>{{CompatGeckoDesktop("44.0")}}<sup>[4]</sup></td>
   <td>{{CompatNo}}</td>
   <td>{{CompatNo}}</td>
   <td>{{CompatUnknown}}</td>
  </tr>
 </tbody>
</table>
</div>

<div id="compat-mobile">
<table class="compat-table">
 <tbody>
  <tr>
   <th>Feature</th>
   <th>Android</th>
   <th>Chrome for Android</th>
   <th>Edge</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>{{CompatUnknown}}</td>
   <td>{{CompatUnknown}}</td>
   <td>{{CompatVersionUnknown}}</td>
   <td>{{CompatUnknown}}</td>
   <td>{{CompatUnknown}}</td>
   <td>{{CompatUnknown}}</td>
   <td>{{CompatUnknown}}</td>
  </tr>
  <tr>
   <td>On disabled form elements</td>
   <td>{{CompatUnknown}}</td>
   <td>{{CompatUnknown}}</td>
   <td>{{CompatNo}}</td>
   <td>{{CompatUnknown}}</td>
   <td>{{CompatUnknown}}</td>
   <td>{{CompatUnknown}}</td>
   <td>{{CompatUnknown}}</td>
  </tr>
 </tbody>
</table>
</div>

<p>[1] Реализовано в <a href="https://crbug.com/236215">bug 236215</a>.</p>

<p>[2] Реализовано в {{bug("432698")}}.</p>

<p>[3] Safari 7 генерирует данное событие во многих ситуациях где это не разрешено, тем самым делая целое событие бесполезным. Смотрите <a href="https://crbug.com/470258">bug 470258</a> for the description of the bug (это также присутствовало в старых версиях Chrome). Safari 8 имеет правильное поведение</p>

<p>[4] Реализовано в {{bug("218093")}}.</p>

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

<ul>
 <li>{{Event("mousedown")}}</li>
 <li>{{Event("mouseup")}}</li>
 <li>{{Event("mousemove")}}</li>
 <li>{{Event("click")}}</li>
 <li>{{Event("dblclick")}}</li>
 <li>{{Event("mouseover")}}</li>
 <li>{{Event("mouseout")}}</li>
 <li>{{Event("mouseenter")}}</li>
 <li>{{Event("mouseleave")}}</li>
 <li>{{Event("contextmenu")}}</li>
</ul>