web api event
Document: pointerlockchange event
The pointerlockchange event is fired when the pointer is locked/unlocked.
The event handler can use pointerLockElement to determine whether the pointer is locked, and if so, to which element it is locked.
This event is not cancelable and does not bubble.
Syntax
Use the event name in methods like addEventListener(), or set an event handler property.
addEventListener("pointerlockchange", (event) => { })
onpointerlockchange = (event) => { }
Event type
A generic Event.
Examples
Using addEventListener():
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:
document.onpointerlockchange = (event) => {
if (document.pointerLockElement)
console.log("The pointer is locked to: ", document.pointerLockElement);
else {
console.log("The pointer is not locked");
}
};
Specifications
SpecificationsStandards references are available on the canonical MDN page.
Browser compatibility
Browser compatibilityCompatibility data is available on the canonical MDN page.