返回到:Prototype – 元素对象
此方法返回元素距文档左上角的偏移量。
此方法返回一个数组,保留元素的 offsetLeft 和 offsetTop。
请注意,所有值都以数字形式返回,尽管它们以像素表示。
语法
element.cumulativeOffset();
返回值
两个数字的数组 [offset left, offset top]。
例子
HTML
x
24
24
1
<html>
2
<head>
3
<title>Prototype examples</title>
4
<script type = "text/javascript" src = "/javascript/prototype.js"></script>
5
6
<script>
7
function getOffset() {
8
var firstElement = $('firstDiv');
9
var arr = firstElement.cumulativeOffset();
10
alert ( "Offset Left: " +arr[0]+ " Offset Top : " +arr[0] );
11
}
12
</script>
13
</head>
14
15
<body>
16
<p>Click getOffset button to see the result.</p>
17
<div id = "firstDiv">
18
<p>This is first paragraph</p>
19
</div>
20
<br />
21
22
<input type ="button" value = "getOffset" onclick = "getOffset();"/>
23
</body>
24
</html>
返回到:Prototype – 元素对象
阅读剩余 40%
作者:terry,如若转载,请注明出处:https://www.web176.com/prototype_api/9135.html