返回到:Prototype – 元素对象
此方法返回元素相对于视口的 X/Y 坐标。返回的位置将是绝对的。
注– 所有值都以数字形式返回,尽管它们以像素表示。
语法
element.viewportOffset();
返回值
数字数组 [Left, Top]。
例子
HTML
x
21
21
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 coordinates = $('visible').viewportOffset();
9
alert("Distance from the Left : " + coordinates[0] );
10
alert("Distance from the Top : " + coordinates[1] );
11
}
12
</script>
13
</head>
14
15
<body>
16
<div id = "visible" style = "position:absolute;left:50px; top:50px;">
17
This is visible division 50 pixels down from the top.
18
</div>
19
<input type = "button" value = "Click" onclick = "showResult();"/>
20
</body>
21
</html>
返回到:Prototype – 元素对象
阅读剩余 33%
作者:terry,如若转载,请注明出处:https://www.web176.com/prototype_api/8974.html