このページはコミュニティーの尽力で英語から翻訳されました。MDN Web Docs コミュニティーについてもっと知り、仲間になるにはこちらから。

View in English Always switch to English

DevicePosture: change イベント

Limited availability

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

Experimental: これは実験的な機能です。
本番で使用する前にブラウザー互換性一覧表をチェックしてください。

changeDevicePosture インターフェイスのイベントで、この端末の形態が変化したときに発生します。例えば、折り曲げ可能な端末が折り曲げ形態 (folded) から平面形態 (continuous) へ移行したときなどです。

構文

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

js
addEventListener("change", (event) => { })

onchange = (event) => { }

イベント型

一般的な Event です。

js
const postureOutput = document.getElementById("currentPosture");

function reportPostureOutput() {
  // type プロパティは "continuous" または "folded" を返す
  postureOutput.textContent = `端末の形態: ${navigator.devicePosture.type}`;
}

navigator.devicePosture.addEventListener("change", reportPostureOutput);

仕様書

Specification
Device Posture API
# dom-deviceposture-onchange

ブラウザーの互換性

関連情報