- Prototype 教程
- 原型 - 主页
- Prototype - 简短概述
- Prototype - 有用功能
- Prototype - 实用方法
- Prototype - 元素对象
- Prototype - 数字处理
- Prototype - 字符串处理
- Prototype - 数组处理
- Prototype - 哈希处理
- Prototype - 基本对象
- Prototype - 模板化
- Prototype - 枚举
- Prototype - 事件处理
- Prototype - 表单管理
- Prototype - JSON 支持
- Prototype - AJAX 支持
- Prototype - 表达范围
- Prototype - 周期执行
- Prototype 实用资源
- Prototype - Quick Guide
- Prototype - 实用资源
- Prototype - 讨论
Prototype - positionedOffset() 方法
此方法返回元素相对其最近定位祖先的偏移。它计算元素及其所有父元素的累积 offsetLeft 和 offsetTop,直到到达位置为静态的元素。
注意 − 请注意,虽然所有值以像素表示,但只返回数字。
语法
element.positionedOffset();
返回值
返回元素相对其最近定位祖先的偏移。
示例
<html>
<head>
<title>Prototype examples</title>
<script type = "text/javascript" src = "/javascript/prototype.js"></script>
<script>
function showResult() {
var arr = $('container2').positionedOffset();
alert("offsetLeft : " + arr[0] );
alert("offsetTop : " + arr[1] );
}
</script>
</head>
<body>
<p>Click the button to see the result.</p>
<br />
<div id = "container1">
<div id = "element"
style = "position:absolute; top: 30px; left: 20px;
border:1px solid red;">
This is the first Element Box
</div>
</div>
<div id = "container2">
<div id = "element"
style = "top: 30px; left: 20px;
border:1px solid red;">
This is the second Element Box
</div>
</div>
<br />
<input type = "button" value = "Click" onclick = "showResult();"/>
</body>
</html>
输出
prototype_element_object.htm
广告