aboutsummaryrefslogtreecommitdiff
path: root/files/zh-cn/web/api/uievent/pagex
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/uievent/pagex
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/uievent/pagex')
-rw-r--r--files/zh-cn/web/api/uievent/pagex/index.html105
1 files changed, 105 insertions, 0 deletions
diff --git a/files/zh-cn/web/api/uievent/pagex/index.html b/files/zh-cn/web/api/uievent/pagex/index.html
new file mode 100644
index 0000000000..b4a7f812f7
--- /dev/null
+++ b/files/zh-cn/web/api/uievent/pagex/index.html
@@ -0,0 +1,105 @@
+---
+title: UIEvent.pageX
+slug: Web/API/UIEvent/pageX
+translation_of: Web/API/UIEvent/pageX
+---
+<p>{{APIRef("DOM Events")}} {{Non-standard_header}}</p>
+
+<p><code><strong>UIEvent.pageX</strong></code> 是只读属性,它返回相对于整个文档的水平坐标。</p>
+
+<h2 id="Syntax" name="Syntax">语法</h2>
+
+<pre class="syntaxbox">var <em>pos</em> = <em>event</em>.pageX</pre>
+
+<h2 id="Syntax" name="Syntax">示例</h2>
+
+<pre><em>var pageX</em> = <em>event</em>.pageX;</pre>
+
+<p><code><em>pageX</em></code>  是鼠标事件触发时,鼠标指针相对于整个文档 X 坐标上像素点的整数值。这一属性同时也参照了页面的水平滚动距离。</p>
+
+<pre class="brush: js">&lt;html&gt;
+&lt;head&gt;
+&lt;title&gt;pageX\pageY &amp; layerX\layerY example&lt;/title&gt;
+
+&lt;script type="text/javascript"&gt;
+
+function showCoords(evt){
+ var form = document.forms.form_coords;
+ var parent_id = evt.target.parentNode.id;
+ form.parentId.value = parent_id;
+ form.pageXCoords.value = evt.pageX;
+ form.pageYCoords.value = evt.pageY;
+ form.layerXCoords.value = evt.layerX;
+ form.layerYCoords.value = evt.layerY;
+}
+
+&lt;/script&gt;
+
+&lt;style type="text/css"&gt;
+
+ #d1 {
+ border: solid blue 1px;
+ padding: 20px;
+ }
+
+ #d2 {
+ position: absolute;
+ top: 180px;
+ left: 80%;
+ right:auto;
+ width: 40%;
+ border: solid blue 1px;
+ padding: 20px;
+ }
+
+ #d3 {
+ position: absolute;
+ top: 240px;
+ left: 20%;
+ width: 50%;
+ border: solid blue 1px;
+ padding: 10px;
+ }
+
+&lt;/style&gt;
+&lt;/head&gt;
+
+&lt;body onmousedown="showCoords(event)"&gt;
+
+&lt;p&gt;To display the mouse coordinates please click anywhere on the page.&lt;/p&gt;
+
+&lt;div id="d1"&gt;
+&lt;span&gt;This is an un-positioned div so clicking it will return
+layerX/layerY values almost the same as pageX/PageY values.&lt;/span&gt;
+&lt;/div&gt;
+
+&lt;div id="d2"&gt;
+&lt;span&gt;This is a positioned div so clicking it will return layerX/layerY
+values that are relative to the top-left corner of this positioned
+element. Note the pageX\pageY properties still return the
+absolute position in the document, including page scrolling.&lt;/span&gt;
+
+&lt;span&gt;Make the page scroll more! This is a positioned div so clicking it
+will return layerX/layerY values that are relative to the top-left
+corner of this positioned element. Note the pageX\pageY properties still
+return the absolute position in the document, including page
+scrolling.&lt;/span&gt;
+&lt;/div&gt;
+
+&lt;div id="d3"&gt;
+&lt;form name="form_coords"&gt;
+ Parent Element id: &lt;input type="text" name="parentId" size="7" /&gt;&lt;br /&gt;
+ pageX:&lt;input type="text" name="pageXCoords" size="7" /&gt;
+ pageY:&lt;input type="text" name="pageYCoords" size="7" /&gt;&lt;br /&gt;
+ layerX:&lt;input type="text" name="layerXCoords" size="7" /&gt;
+ layerY:&lt;input type="text" name="layerYCoords" size="7" /&gt;
+&lt;/form&gt;
+&lt;/div&gt;
+
+&lt;/body&gt;
+&lt;/html&gt;
+</pre>
+
+<h2 id="Specification" name="Specification">规范</h2>
+
+<p>这一属性不在规范中。</p>