aboutsummaryrefslogtreecommitdiff
path: root/files/zh-cn/web/api/window/screentop/index.html
diff options
context:
space:
mode:
authorPeter Bengtsson <mail@peterbe.com>2020-12-08 14:40:17 -0500
committerPeter Bengtsson <mail@peterbe.com>2020-12-08 14:40:17 -0500
commit33058f2b292b3a581333bdfb21b8f671898c5060 (patch)
tree51c3e392513ec574331b2d3f85c394445ea803c6 /files/zh-cn/web/api/window/screentop/index.html
parent8b66d724f7caf0157093fb09cfec8fbd0c6ad50a (diff)
downloadtranslated-content-33058f2b292b3a581333bdfb21b8f671898c5060.tar.gz
translated-content-33058f2b292b3a581333bdfb21b8f671898c5060.tar.bz2
translated-content-33058f2b292b3a581333bdfb21b8f671898c5060.zip
initial commit
Diffstat (limited to 'files/zh-cn/web/api/window/screentop/index.html')
-rw-r--r--files/zh-cn/web/api/window/screentop/index.html88
1 files changed, 88 insertions, 0 deletions
diff --git a/files/zh-cn/web/api/window/screentop/index.html b/files/zh-cn/web/api/window/screentop/index.html
new file mode 100644
index 0000000000..35067bb48d
--- /dev/null
+++ b/files/zh-cn/web/api/window/screentop/index.html
@@ -0,0 +1,88 @@
+---
+title: Window.screenTop
+slug: Web/API/Window/screenTop
+translation_of: Web/API/Window/screenTop
+---
+<p>{{APIRef}}</p>
+
+<p><code><strong>Window.screenTop</strong></code> 只读属性返回垂直距离,单位是CSS 像素, 从用户浏览器的上边界到屏幕最顶端。</p>
+
+<div class="blockIndicator note">
+<p><strong>Note</strong>: <code>screenTop</code> is an alias of the older {{domxref("Window.screenY")}} property. <code>screenTop</code> was originally supported only in IE but was introduced everywhere due to popularity.</p>
+</div>
+
+<h2 id="Syntax" name="Syntax">语法</h2>
+
+<pre class="syntaxbox"><em>topWindowPos</em> = window.screenTop
+</pre>
+
+<h3 id="返回值">返回值</h3>
+
+<p>A number equal to the number of CSS pixels from the top edge of the browser viewport to the  top edge of the screen.</p>
+
+<h2 id="Specifications" name="Specifications">例子</h2>
+
+<p>In our <a href="https://mdn.github.io/dom-examples/screenleft-screentop/">screenleft-screentop</a> example, you'll see a canvas onto which has been drawn a circle. In this example we are using <code>screenLeft</code>/<code>screenTop</code> plus {{domxref("Window.requestAnimationFrame()")}} to constantly redraw the circle in the same physical position on the screen, even if the window position is moved.</p>
+
+<pre class="brush: js">initialLeft = window.screenLeft + canvasElem.offsetLeft;
+initialTop = window.screenTop + canvasElem.offsetTop;
+
+function positionElem() {
+ let newLeft = window.screenLeft + canvasElem.offsetLeft;
+ let newTop = window.screenTop + canvasElem.offsetTop;
+
+ let leftUpdate = initialLeft - newLeft;
+ let topUpdate = initialTop - newTop;
+
+ ctx.fillStyle = 'rgb(0, 0, 0)';
+ ctx.fillRect(0, 0, width, height);
+ ctx.fillStyle = 'rgb(0, 0, 255)';
+ ctx.beginPath();
+ ctx.arc(leftUpdate + (width/2), topUpdate + (height/2) + 35, 50, degToRad(0), degToRad(360), false);
+ ctx.fill();
+
+ pElem.textContent = 'Window.screenLeft: ' + window.screenLeft + ', Window.screenTop: ' + window.screenTop;
+
+ window.requestAnimationFrame(positionElem);
+}
+
+window.requestAnimationFrame(positionElem);</pre>
+
+<p>Also in the code we include a snippet that detects whether <code>screenLeft</code> is supported, and if not, polyfills in <code>screenLeft</code>/<code>screenTop</code> using {{domxref("Window.screenX")}}/{{domxref("Window.screenY")}}.</p>
+
+<pre class="brush: js">if(!window.screenLeft) {
+ window.screenLeft = window.screenX;
+ window.screenTop = window.screenY;
+}</pre>
+
+<h2 id="Specifications" name="Specifications">说明</h2>
+
+<table class="standard-table" style="height: 49px; width: 1000px;">
+ <thead>
+ <tr>
+ <th scope="col">Specification</th>
+ <th scope="col">Status</th>
+ <th scope="col">Comment</th>
+ </tr>
+ </thead>
+ <tbody>
+ <tr>
+ <td>{{ SpecName('CSSOM View', '#dom-window-screeny', 'Window.screenTop') }}</td>
+ <td>{{ Spec2('CSSOM View') }}</td>
+ <td>Initial definition.</td>
+ </tr>
+ </tbody>
+</table>
+
+<h2 id="浏览器兼容性">浏览器兼容性</h2>
+
+
+
+<p>{{Compat("api.Window.screenTop")}}</p>
+
+<h2 id="参考">参考</h2>
+
+<ul>
+ <li>{{domxref("window.screenLeft")}}</li>
+ <li>{{domxref("Window.screenY")}}</li>
+</ul>