diff options
author | Peter Bengtsson <mail@peterbe.com> | 2020-12-08 14:40:17 -0500 |
---|---|---|
committer | Peter Bengtsson <mail@peterbe.com> | 2020-12-08 14:40:17 -0500 |
commit | 33058f2b292b3a581333bdfb21b8f671898c5060 (patch) | |
tree | 51c3e392513ec574331b2d3f85c394445ea803c6 /files/zh-cn/web/api/screen/orientation | |
parent | 8b66d724f7caf0157093fb09cfec8fbd0c6ad50a (diff) | |
download | translated-content-33058f2b292b3a581333bdfb21b8f671898c5060.tar.gz translated-content-33058f2b292b3a581333bdfb21b8f671898c5060.tar.bz2 translated-content-33058f2b292b3a581333bdfb21b8f671898c5060.zip |
initial commit
Diffstat (limited to 'files/zh-cn/web/api/screen/orientation')
-rw-r--r-- | files/zh-cn/web/api/screen/orientation/index.html | 69 |
1 files changed, 69 insertions, 0 deletions
diff --git a/files/zh-cn/web/api/screen/orientation/index.html b/files/zh-cn/web/api/screen/orientation/index.html new file mode 100644 index 0000000000..0a06678a03 --- /dev/null +++ b/files/zh-cn/web/api/screen/orientation/index.html @@ -0,0 +1,69 @@ +--- +title: Screen.orientation +slug: Web/API/Screen/orientation +tags: + - API + - Experimental + - Screen Orientation + - screen +translation_of: Web/API/Screen/orientation +--- +<p>{{APIRef("Screen Orientation API")}}{{SeeCompatTable}}</p> + +<p><strong><code>orientation</code></strong> 是 {{DOMxRef("Screen")}} 接口的一个只读属性,返回屏幕当前的方向。</p> + +<h2 id="语法">语法</h2> + +<pre class="syntaxbox">var <var>orientation</var> = window.screen.orientation;</pre> + +<h3 id="返回值">返回值</h3> + +<p>一个 {{DOMxRef("ScreenOrientation")}} 的实例,表示屏幕的方向。</p> + +<p>注意在更早的、有前缀的版本中会返回一个 {{DOMxRef("DOMString")}} 值,相当于 {{DOMxRef("ScreenOrientation.type")}} 的值。</p> + +<h2 id="示例">示例</h2> + +<pre class="brush: js;">var orientation = (screen.orientation || {}).type || screen.mozOrientation || screen.msOrientation; + +if (orientation === "landscape-primary") { + console.log("That looks good."); +} else if (orientation === "landscape-secondary") { + console.log("Mmmh... the screen is upside down!"); +} else if (orientation === "portrait-secondary" || orientation === "portrait-primary") { + console.log("Mmmh... you should rotate your device to landscape"); +} else if (orientation === undefined) { + console.log("The orientation API isn't supported in this browser :("); +} +</pre> + +<h2 id="规范">规范</h2> + +<table class="standard-table"> + <thead> + <tr> + <th scope="col">规范</th> + <th scope="col">状态</th> + <th scope="col">备注</th> + </tr> + </thead> + <tbody> + <tr> + <td>{{SpecName('Screen Orientation', '#dom-screen-orientation', 'orientation')}}</td> + <td>{{Spec2('Screen Orientation')}}</td> + <td>Initial definition</td> + </tr> + </tbody> +</table> + +<h2 id="浏览器兼容性">浏览器兼容性</h2> + +<p>{{Compat("api.Screen.orientation")}}</p> + +<h2 id="参见">参见</h2> + +<ul> + <li>{{DOMxRef("ScreenOrientation")}}</li> + <li>{{DOMxRef("Screen.onorientationchange")}}</li> + <li><a href="/en-US/docs/Managing_screen_orientation">Managing screen orientation</a></li> +</ul> |