Screen: orientation-Eigenschaft
Baseline
Widely available
This feature is well established and works across many devices and browser versions. It’s been available across browsers since März 2023.
Die orientation-Eigenschaft, eine schreibgeschützte Eigenschaft der Screen-Schnittstelle, gibt die aktuelle Ausrichtung des Bildschirms zurück.
Wert
Eine Instanz von ScreenOrientation, die die Ausrichtung des Bildschirms darstellt.
Beachten Sie, dass ältere, mit Präfix versehene Versionen einen String zurückgaben, der dem ScreenOrientation.type entspricht.
Beispiele
js
switch (screen.orientation.type) {
case "landscape-primary":
console.log("That looks good.");
break;
case "landscape-secondary":
console.log("Mmm… the screen is upside down!");
break;
case "portrait-secondary":
case "portrait-primary":
console.log("Mmm… you should rotate your device to landscape");
break;
default:
console.log("The orientation API isn't supported in this browser :(");
}
Spezifikationen
| Specification |
|---|
| Screen Orientation> # dom-screen-orientation> |
Browser-Kompatibilität
Loading…