Skip to content

Commit 6e5b16a

Browse files
allan-bonadioAllan BonadiowbambergJosh-Cena
authored
mouse & pointer event pages updates (#36993)
* Added cross-links between individual mouse events and pointer events * added more info about pointer/mouse analogy and differences. Added details that were missing. * a few typos * Minor edits --------- Co-authored-by: Allan Bonadio <[email protected]> Co-authored-by: wbamberg <[email protected]> Co-authored-by: Joshua Chen <[email protected]>
1 parent b8892c8 commit 6e5b16a

File tree

14 files changed

+41
-7
lines changed

14 files changed

+41
-7
lines changed

files/en-us/web/api/element/mousedown_event/index.md

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,9 @@ browser-compat: api.Element.mousedown_event
1010

1111
The **`mousedown`** event is fired at an {{domxref("Element")}} when a pointing device button is pressed while the pointer is inside the element.
1212

13-
> [!NOTE]
14-
> This differs from the {{domxref("Element/click_event", "click")}} event in that `click` is fired after a full click action occurs; that is, the mouse button is pressed and released while the pointer remains inside the same element. `mousedown` is fired the moment the button is initially pressed.
13+
This differs from the {{domxref("Element/click_event", "click")}} event in that `click` is fired after a full click action occurs; that is, the mouse button is pressed and released while the pointer remains inside the same element. `mousedown` is fired the moment the button is initially pressed.
14+
15+
This behavior is different from {{domxref("Element/pointerdown_event", "pointerdown")}} events. When using a physical mouse, `mousedown` events fire whenever any button on a mouse is pressed down. `pointerdown` events fire only upon the first button press; subsequent button presses don't fire `pointerdown` events.
1516

1617
## Syntax
1718

@@ -105,3 +106,4 @@ See [`mousemove` event](/en-US/docs/Web/API/Element/mousemove_event#examples) fo
105106
- {{domxref("Element/mouseenter_event", "mouseenter")}}
106107
- {{domxref("Element/mouseleave_event", "mouseleave")}}
107108
- {{domxref("Element/contextmenu_event", "contextmenu")}}
109+
- {{domxref("Element/pointerdown_event", "pointerdown")}}

files/en-us/web/api/element/mouseenter_event/index.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,10 +82,11 @@ _This interface also inherits properties of its parents, {{domxref("UIEvent")}}
8282

8383
## Usage notes
8484

85-
Though similar to {{domxref("Element/mouseover_event", "mouseover")}}, `mouseenter` differs in that it doesn't [bubble](/en-US/docs/Web/API/Event/bubbles) and it isn't sent to any descendants when the pointer is moved from one of its descendants' physical space to its own physical space.
85+
Though similar to {{domxref("Element/mouseover_event", "mouseover")}}, `mouseenter` differs in that it doesn't [bubble](/en-US/docs/Web/API/Event/bubbles) and it isn't sent to any descendants when the pointer is moved from one of its descendants' physical space to its own physical space. Other than that, enter and over events for the same situation are dispatched at the same time, if appropriate.
8686

8787
### Behavior of `mouseenter` events
8888

89+
This describes the mouseenter events received by each of four concentric divs with no padding or margin, so the events all happen at the same time:
8990
![Mouseenter behavior diagram](mouseenter.png)
9091
One `mouseenter` event is sent to each element of the hierarchy when entering them. Here 4 events are sent to the four elements of the hierarchy when the pointer reaches the text.
9192

@@ -187,3 +188,4 @@ function addListItem(text) {
187188
- {{domxref("Element/mouseout_event", "mouseout")}}
188189
- {{domxref("Element/mouseleave_event", "mouseleave")}}
189190
- {{domxref("Element/contextmenu_event", "contextmenu")}}
191+
- {{domxref("Element/pointerenter_event", "pointerenter")}}

files/en-us/web/api/element/mouseleave_event/index.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ browser-compat: api.Element.mouseleave_event
1010

1111
The **`mouseleave`** event is fired at an {{domxref("Element")}} when the cursor of a pointing device (usually a mouse) is moved out of it.
1212

13-
`mouseleave` and {{domxref("Element/mouseout_event", "mouseout")}} are similar but differ in that `mouseleave` does not bubble and `mouseout` does. This means that `mouseleave` is fired when the pointer has exited the element _and_ all of its descendants, whereas `mouseout` is fired when the pointer leaves the element _or_ leaves one of the element's descendants (even if the pointer is still within the element).
13+
`mouseleave` and {{domxref("Element/mouseout_event", "mouseout")}} are similar but differ in that `mouseleave` does not bubble and `mouseout` does. This means that `mouseleave` is fired when the pointer has exited the element _and_ all of its descendants, whereas `mouseout` is fired when the pointer leaves the element _or_ leaves one of the element's descendants, because of bubbling (even if the pointer is still within the element). Other than that, leave and out events for the same situation are dispatched at the same time, if appropriate.
1414

1515
The `mouseleave` and `mouseout` events will not be triggered when the element is replaced or removed from the DOM.
1616

@@ -185,3 +185,4 @@ function addListItem(text) {
185185
- {{domxref("Element/mouseout_event", "mouseout")}}
186186
- {{domxref("Element/mouseenter_event", "mouseenter")}}
187187
- {{domxref("Element/contextmenu_event", "contextmenu")}}
188+
- {{domxref("Element/pointerleave_event", "pointerleave")}}

files/en-us/web/api/element/mousemove_event/index.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@ browser-compat: api.Element.mousemove_event
1010

1111
The `mousemove` event is fired at an element when a pointing device (usually a mouse) is moved while the cursor's hotspot is inside it.
1212

13+
These events happen whether or not any mouse buttons are pressed. They can fire at a very high rate, depends on how fast the user moves the mouse, how fast the machine is, what other tasks and processes are happening, etc.
14+
1315
## Syntax
1416

1517
Use the event name in methods like {{domxref("EventTarget.addEventListener", "addEventListener()")}}, or set an event handler property.
@@ -181,3 +183,4 @@ function drawLine(context, x1, y1, x2, y2) {
181183
- {{domxref("Element/mouseenter_event", "mouseenter")}}
182184
- {{domxref("Element/mouseleave_event", "mouseleave")}}
183185
- {{domxref("Element/contextmenu_event", "contextmenu")}}
186+
- {{domxref("Element/pointermove_event", "pointermove")}}

files/en-us/web/api/element/mouseout_event/index.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@ The **`mouseout`** event is fired at an {{domxref("Element")}} when a pointing d
1212

1313
`mouseout` is also delivered to an element if the cursor enters a child element, because the child element obscures the visible area of the element.
1414

15+
If the target element has child elements, `mouseout` and `mouseover` events fire as the mouse moves over the boundaries of these elements too, not just the target element itself. Usually, {{domxref("Element/mouseenter_event", "mouseenter")}} and {{domxref("Element/mouseleave_event", "mouseleave")}} events' behavior is more sensible, because they are not affected by moving into child elements.
16+
1517
## Syntax
1618

1719
Use the event name in methods like {{domxref("EventTarget.addEventListener", "addEventListener()")}}, or set an event handler property.
@@ -161,3 +163,4 @@ test.addEventListener(
161163
- {{domxref("Element/mouseenter_event", "mouseenter")}}
162164
- {{domxref("Element/mouseleave_event", "mouseleave")}}
163165
- {{domxref("Element/contextmenu_event", "contextmenu")}}
166+
- {{domxref("Element/pointerout_event", "pointerout")}}

files/en-us/web/api/element/mouseover_event/index.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@ browser-compat: api.Element.mouseover_event
1010

1111
The **`mouseover`** event is fired at an {{domxref("Element")}} when a pointing device (such as a mouse or trackpad) is used to move the cursor onto the element or one of its child elements.
1212

13+
If the target element has child elements, `mouseout` and `mouseover` events fire as the mouse moves over the boundaries of these elements too, not just the target element itself. Usually, `mouseenter` and `mouseleave` events' behavior is more sensible, because they are not affected by moving into child elements.
14+
1315
## Syntax
1416

1517
Use the event name in methods like {{domxref("EventTarget.addEventListener", "addEventListener()")}}, or set an event handler property.
@@ -154,3 +156,4 @@ test.addEventListener(
154156
- {{domxref("Element/mouseenter_event", "mouseenter")}}
155157
- {{domxref("Element/mouseleave_event", "mouseleave")}}
156158
- {{domxref("Element/contextmenu_event", "contextmenu")}}
159+
- {{domxref("Element/pointerover_event", "pointerover")}}

files/en-us/web/api/element/mouseup_event/index.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@ The **`mouseup`** event is fired at an {{domxref("Element")}} when a button on a
1212

1313
`mouseup` events are the counterpoint to {{domxref("Element.mousedown_event", "mousedown")}} events.
1414

15+
This behavior is different from {{domxref("Element/pointerup_event", "pointerup")}} events. When using a physical mouse, `mouseup` events fire whenever any button on a mouse is released. `pointerup` events fire only upon the last button release; previous button releases, while other buttons are held down, don't fire `pointerup` events.
16+
1517
## Syntax
1618

1719
Use the event name in methods like {{domxref("EventTarget.addEventListener", "addEventListener()")}}, or set an event handler property.
@@ -104,3 +106,4 @@ See [`mousemove` event](/en-US/docs/Web/API/Element/mousemove_event#examples) fo
104106
- {{domxref("Element/mouseenter_event", "mouseenter")}}
105107
- {{domxref("Element/mouseleave_event", "mouseleave")}}
106108
- {{domxref("Element/contextmenu_event", "contextmenu")}}
109+
- {{domxref("Element/pointerup_event", "pointerup")}}

files/en-us/web/api/element/pointerdown_event/index.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@ browser-compat: api.Element.pointerdown_event
1010

1111
The `pointerdown` event is fired when a pointer becomes active. For mouse, it is fired when the device transitions from no buttons pressed to at least one button pressed. For touch, it is fired when physical contact is made with the digitizer. For pen, it is fired when the stylus makes physical contact with the digitizer.
1212

13+
This behavior is different from {{domxref("Element/mousedown_event", "mousedown")}} events. When using a physical mouse, `mousedown` events fire whenever any button on a mouse is pressed down. `pointerdown` events fire only upon the first button press; subsequent button presses don't fire `pointerdown` events.
14+
1315
> [!NOTE]
1416
> For touchscreen browsers that allow [direct manipulation](https://w3c.github.io/pointerevents/#dfn-direct-manipulation), a `pointerdown` event triggers [implicit pointer capture](https://w3c.github.io/pointerevents/#dfn-implicit-pointer-capture), which causes the target to capture all subsequent pointer events as if they were occurring over the capturing target. Accordingly, `pointerover`, `pointerenter`, `pointerleave`, and `pointerout` **will not fire** as long as this capture is set. The capture can be released manually by calling {{domxref('element.releasePointerCapture')}} on the target element, or it will be implicitly released after a `pointerup` or `pointercancel` event.
1517
@@ -104,3 +106,4 @@ para.onpointerdown = (event) => {
104106
- {{domxref('Element/pointerout_event', 'pointerout')}}
105107
- {{domxref('Element/pointerleave_event', 'pointerleave')}}
106108
- {{domxref('Element/pointerrawupdate_event', 'pointerrawupdate')}}
109+
- {{domxref("Element/mousedown_event", "mousedown")}}

files/en-us/web/api/element/pointerenter_event/index.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ browser-compat: api.Element.pointerenter_event
88

99
{{APIRef}}
1010

11-
The `pointerenter` event fires when a pointing device is moved into the hit test boundaries of an element or one of its descendants, including as a result of a {{domxref("Element/pointerdown_event", "pointerdown")}} event from a device that does not support hover (see {{domxref("Element/pointerdown_event", "pointerdown")}}).
11+
The `pointerenter` event fires when a pointing device is moved into the hit test boundaries of an element or one of its descendants, including as a result of a {{domxref("Element/pointerdown_event", "pointerdown")}} event from a device that does not support hover (see {{domxref("Element/pointerdown_event", "pointerdown")}}). Otherwise, `pointerenter` works the same as {{domxref("Element/mouseenter_event", "mouseenter")}}, and are dispatched at the same time. They are also dispatched at the same time as {{domxref("Element/mouseover_event", "mouseover")}} and {{domxref("Element/pointerover_event", "pointerover")}} events, if appropriate.
1212

1313
## Syntax
1414

@@ -101,3 +101,4 @@ para.onpointerenter = (event) => {
101101
- {{domxref('Element/pointerout_event', 'pointerout')}}
102102
- {{domxref('Element/pointerleave_event', 'pointerleave')}}
103103
- {{domxref('Element/pointerrawupdate_event', 'pointerrawupdate')}}
104+
- {{domxref("Element/mouseenter_event", "mouseenter")}}

files/en-us/web/api/element/pointerleave_event/index.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ browser-compat: api.Element.pointerleave_event
88

99
{{APIRef}}
1010

11-
The `pointerleave` event is fired when a pointing device is moved out of the hit test boundaries of an element. For pen devices, this event is fired when the stylus leaves the hover range detectable by the digitizer.
11+
The `pointerleave` event is fired when a pointing device is moved out of the hit test boundaries of an element. For pen devices, this event is fired when the stylus leaves the hover range detectable by the digitizer. Otherwise, `pointerleave` works the same as {{domxref("Element/mouseleave_event", "mouseleave")}}, and are dispatched at the same time. They are also dispatched at the same time as {{domxref("Element/mouseout_event", "mouseout")}} and {{domxref("Element/pointerout_event", "pointerout")}} events, if appropriate.
1212

1313
## Syntax
1414

@@ -101,3 +101,4 @@ para.onpointerleave = (event) => {
101101
- {{domxref('Element/pointercancel_event', 'pointercancel')}}
102102
- {{domxref('Element/pointerout_event', 'pointerout')}}
103103
- {{domxref('Element/pointerrawupdate_event', 'pointerrawupdate')}}
104+
- {{domxref("Element/mouseleave_event", "mouseleave")}}

0 commit comments

Comments
 (0)