HTMLElement: pointercancel event

翻译不完整。 请帮助我们翻译这篇文章!

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

Bubbles Yes
Cancelable No
Interface PointerEvent
Event handler property onpointercancel

常见需要 pointercancel 事件的地方:

  • 用户在使用指针设备时按了硬件按钮,如用户打开任务切换界面或者按下手机的“Home”键;
  • 指针正在使用时屏幕旋转;
  • 浏览器认为用户不小心按了指针设备。例如,用户把手掌放在触摸屏上,触发了手掌检测;
  • touch-action CSS 属性不允许继续输入。

在 pointercancel 事件触发后,浏览器会按顺序发送 pointerout 以及 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
Pointer Events Obsolete

浏览器兼容性

Update compatibility data on GitHub
DesktopMobile
ChromeEdgeFirefoxInternet ExplorerOperaSafariAndroid webviewChrome for AndroidFirefox for AndroidOpera for AndroidSafari on iOSSamsung Internet
pointercancel eventChrome Full support 55Edge Full support 12
Full support 12
No support 12 — 79
Alternate Name
Alternate Name Uses the non-standard name: mspointercancel
Firefox Full support 59
Full support 59
Full support 29
Disabled
Disabled From version 29: this feature is behind the dom.w3c_pointer_events.enabled preference (needs to be set to true). To change preferences in Firefox, visit about:config.
IE Full support 11
Full support 11
Full support 10
Alternate Name
Alternate Name Uses the non-standard name: mspointercancel
Opera ? Safari No support NoWebView Android Full support 55Chrome Android Full support 55Firefox Android Full support 29
Disabled
Full support 29
Disabled
Disabled From version 29: this feature is behind the dom.w3c_pointer_events.enabled preference (needs to be set to true). To change preferences in Firefox, visit about:config.
Opera Android ? Safari iOS No support NoSamsung Internet Android Full support 6.0

Legend

Full support  
Full support
No support  
No support
Compatibility unknown  
Compatibility unknown
User must explicitly enable this feature.
User must explicitly enable this feature.
Uses a non-standard name.
Uses a non-standard name.

参见