跳转到主要内容

Element: pointerleave event

{{APIRef("Pointer Events")}}

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.

Syntax

Use the event name in {{domxref("EventTarget/addEventListener", "addEventListener()")}}:

addEventListener("pointerleave", (event) => { })

Alternatively, assign to the event handler property of the interface:

onpointerleave = (event) => { }

Event type

A {{domxref("PointerEvent")}}. Inherits from {{domxref("Event")}}.

{{InheritanceDiagram("PointerEvent")}}

Examples

Using addEventListener():

const para = document.querySelector("p");

para.addEventListener("pointerleave", (event) => {
  console.log("Pointer left element");
});

Using the onpointerleave event handler property (but note that this replaces other event listeners added using onpointerleave, if any):

const para = document.querySelector("p");

para.onpointerleave = (event) => {
  console.log("Pointer left element");
};

Specifications

{{Specifications}}

Browser compatibility

{{Compat}}

See also