Document: pointerlockchange イベント

Limited availability

This feature is not Baseline because it does not work in some of the most widely-used browsers.

pointerlockchange イベントは、ポインターがロックされたり解除されたりしたときに発行されます。

イベントハンドラーは Document.pointerLockElement を使用して、ポインターがロックされているかどうか、ロックされている場合はどの要素にロックされているかを判断することができます。

このイベントはキャンセル不可で、バブリングしません。

構文

このイベント名を addEventListener() などのメソッドで使用するか、イベントハンドラーのプロパティを設定するかしてください。

js
addEventListener("pointerlockchange", (event) => {});

onpointerlockchange = (event) => {};

イベント型

一般的な Event です。

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");
  }
});

onpointerlockchange イベントハンドラープロパティを使用した場合

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

ブラウザーの互換性

Report problems with this compatibility data on GitHub
desktopmobile
Chrome
Edge
Firefox
Opera
Safari
Chrome Android
Firefox for Android
Opera Android
Safari on iOS
Samsung Internet
WebView Android
WebView on iOS
pointerlockchange event

Legend

Tip: you can click/tap on a cell for more information.

Full support
Full support
No support
No support
Requires a vendor prefix or different name for use.
Has more compatibility info.

関連情報