Element.requestPointerLock()

实验性: 这是一项实验性技术
在将其用于生产之前,请仔细检查浏览器兼容性表格

Element.requestPointerLock() 方法允许你异步地请求将鼠标指针锁定在指定元素上。

若想追踪请求成功还是失败,则需要在 Document 级别监听 pointerlockchangepointerlockerror (en-US) 事件。

语法

instanceOfElement.requestPointerLock();

规范

Specification
Pointer Lock 2.0
# dom-element-requestpointerlock

浏览器兼容性

BCD tables only load in the browser

参见