--- title: 'HTMLElement: pointercancel event' slug: Web/API/HTMLElement/pointercancel_event translation_of: Web/API/HTMLElement/pointercancel_event ---
{{APIRef}}

当浏览器认为不再会有更多的指针事件, 或者在 {{event("pointerdown")}} 事件触发之后用户滚动或者缩放窗口,pointercancel 事件被触发。

Bubbles Yes
Cancelable No
Interface {{domxref("PointerEvent")}}
Event handler property onpointercancel

常见需要 pointercancel 事件的地方:

在 pointercancel 事件触发后,浏览器会按顺序发送 {{event("pointerout")}} 以及 {{event("pointerleave")}}。

示例

使用 addEventListener():

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

para.addEventListener('pointercancel', (event) => {
  console.log('Pointer event cancelled');
});

使用 onpointercancel 事件句柄属性:

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

para.onpointercancel = (event) => {
  console.log('Pointer event cancelled');
};

Specifications

Specification Status
{{SpecName('Pointer Events', '#the-pointercancel-event')}} {{Spec2('Pointer Events')}}

浏览器兼容性

{{Compat("api.HTMLElement.pointercancel_event")}}

参见