返回到:Prototype – 元素对象
此方法返回元素相对于视口的 X/Y 坐标。返回的位置将是绝对的。
注– 所有值都以数字形式返回,尽管它们以像素表示。
语法
element.viewportOffset();
返回值
数字数组 [Left, Top]。
例子
<html>
<head>
<title>Prototype examples</title>
<script type = "text/javascript" src = "/javascript/prototype.js"></script>
<script>
function showResult() {
var coordinates = $('visible').viewportOffset();
alert("Distance from the Left : " + coordinates[0] );
alert("Distance from the Top : " + coordinates[1] );
}
</script>
</head>
<body>
<div id = "visible" style = "position:absolute;left:50px; top:50px;">
This is visible division 50 pixels down from the top.
</div>
<input type = "button" value = "Click" onclick = "showResult();"/>
</body>
</html>返回到:Prototype – 元素对象
作者:terry,如若转载,请注明出处:https://www.web176.com/prototype_api/8974.html
支付宝
微信