Document:pointerLockElement 属性

Document 接口的 pointerLockElement 只读属性提供了指针锁定时鼠标事件的目标元素。如果指针处于锁定等待中、指针没有被锁定或目标元素在另外一个文档中,返回 null

一个 Elementnull

示例

确定一个 canvas 元素当前是否被指针锁定。

js
if (document.pointerLockElement === canvasElement) {
  console.log("指针当前已锁定");
  // 做一些有用的响应
} else {
  console.log("指针当前已解锁");
  // 做一些有用的响应
}

规范

Specification
Pointer Lock 2.0
# dom-documentorshadowroot-pointerlockelement

浏览器兼容性

BCD tables only load in the browser

参见