返回到:Prototype – 元素对象
此方法返回 element.s 相对于其位置最近的祖先的偏移量。这将计算一个元素及其所有父元素的累积offsetLeft和offsetTop,直到它到达具有静态位置的元素。
注意– 请注意,尽管所有值都以像素表示,但它们仅以数字形式返回。
语法
element.positionedOffset();
返回值
返回 element.s 相对于其位置最近的祖先的偏移量。
例子
HTML
x
38
38
1
<html>
2
<head>
3
<title>Prototype examples</title>
4
<script type = "text/javascript" src = "/javascript/prototype.js"></script>
5
6
<script>
7
function showResult() {
8
var arr = $('container2').positionedOffset();
9
alert("offsetLeft : " + arr[0] );
10
alert("offsetTop : " + arr[1] );
11
}
12
</script>
13
</head>
14
15
<body>
16
<p>Click the button to see the result.</p>
17
<br />
18
19
<div id = "container1">
20
<div id = "element"
21
style = "position:absolute; top: 30px; left: 20px;
22
border:1px solid red;">
23
This is the first Element Box
24
</div>
25
</div>
26
27
<div id = "container2">
28
<div id = "element"
29
style = "top: 30px; left: 20px;
30
border:1px solid red;">
31
This is the second Element Box
32
</div>
33
</div>
34
<br />
35
36
<input type = "button" value = "Click" onclick = "showResult();"/>
37
</body>
38
</html>
返回到:Prototype – 元素对象
阅读剩余 84%
作者:terry,如若转载,请注明出处:https://www.web176.com/prototype_api/9059.html