blob: 6c504d3f52bf5197e6da535dce268a28f9f964f5 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
|
---
title: event.pageY
slug: Web/API/UIEvent/pageY
translation_of: Web/API/UIEvent/pageY
---
<p>{{ ApiRef() }}</p>
<h3 id="Summary" name="Summary">概述</h3>
<p>返回事件发生时相对于整个文档的纵坐标.</p>
<h3 id="Syntax" name="Syntax">语法</h3>
<pre class="eval"><em>var pageY</em> = <em>event</em>.pageY;
</pre>
<p><code>pageY</code> 是事件发生时鼠标指针所在位置相对于整个文档的纵坐标,单位为像素.该属性会考虑到页面滚动条的高度.</p>
<h3 id="Example" name="Example">例子</h3>
<pre><html>
<head>
<title>pageX\pageY & layerX\layerY example</title>
<script type="text/javascript">
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;
}
</script>
<style type="text/css">
#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;
}
</style>
</head>
<body onmousedown="showCoords(event)">
<p>要显示鼠标所在位置的坐标,请点击页面上的任意地方.</p>
<div id="d1">
<span>这是一个未定位的div(没有指定css position属性),所以点击它返回的layerX/layerY值几乎和pageX/PageY值完全相同.</span>
</div>
<div id="d2">
<span><span id="result_box" lang="zh-CN"><span>这是一个</span><span>已定位的div</span><span>,因此</span><span>点击它</span><span>时返回</span><span>的layerX</span><span>/</span><span class="hps">layerY的值是相对于自己左上角(</span></span>top-left<span id="result_box" lang="zh-CN"><span class="hps">)位置的坐标值.</span>
<span>然而</span><span>pageX</span><span>/</span><span class="hps">pageY</span><span>属性</span><span>仍</span><span>返回该div在</span><span>文档中</span><span>的</span><span>绝对位置</span><span>,</span><span>包括页面</span><span>滚动</span></span>高度.</span>
</div>
<div id="d3">
<form name="form_coords">
父元素id: <input type="text" name="parentId" size="7" /><br />
pageX:<input type="text" name="pageXCoords" size="7" />
pageY:<input type="text" name="pageYCoords" size="7" /><br />
layerX:<input type="text" name="layerXCoords" size="7" />
layerY:<input type="text" name="layerYCoords" size="7" />
</form>
</div>
</body>
</html>
</pre>
<h3 id="Specification" name="Specification">规范</h3>
<p>不属于任何公开的标准.</p>
<p>{{ languages( {"pl": "pl/DOM/event.pageY","en": "en/DOM/event.pageY" } ) }}</p>
|