The pointerlockchange
event is fired when the pointer is locked/unlocked.
The event handler can use Document.pointerLockElement
to determine whether the pointer is locked, and if so, to which element it is locked.
This event is not cancelable.
The pointerlockchange
event is fired when the pointer is locked/unlocked.
The event handler can use Document.pointerLockElement
to determine whether the pointer is locked, and if so, to which element it is locked.
This event is not cancelable.
Use the event name in methods like addEventListener()
, or set an event handler property.
js
addEventListener("pointerlockchange", (event) => {}); onpointerlockchange = (event) => {};
A generic Event
.
Using addEventListener()
:
js
addEventListener("pointerlockchange", (event) => { if (document.pointerLockElement) console.log("The pointer is locked to: ", document.pointerLockElement); else { console.log("The pointer is not locked"); } });
Using the onpointerlockchange
event handler property:
js
document.onpointerlockchange = (event) => { if (document.pointerLockElement) console.log("The pointer is locked to: ", document.pointerLockElement); else { console.log("The pointer is not locked"); } };
Specification |
---|
Pointer Lock 2.0 # pointerlockchange-and-pointerlockerror-events |
Pointer Lock 2.0 # dom-document-onpointerlockchange |
Desktop | Mobile | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|
Chrome | Edge | Firefox | Internet Explorer | Opera | Safari | WebView Android | Chrome Android | Firefox for Android | Opera Android | Safari on IOS | Samsung Internet | |
pointerlockchange_event |
3622–38 | 13 | 5014–50 | No | 2315–25 | 10.1 | 374.4–38 | 3625–38 | 5014–50 | 2414–25 | No | 3.01.5–3.0 |
© 2005–2023 MDN contributors.
Licensed under the Creative Commons Attribution-ShareAlike License v2.5 or later.
https://developer.mozilla.org/en-US/docs/Web/API/Document/pointerlockchange_event