- Prototype 教程
- Prototype - 主页
- Prototype - 简要概述
- Prototype - 有用功能
- Prototype - 实用方法
- Prototype - 元素对象
- Prototype - 数字处理
- Prototype - 字符串处理
- Prototype - 数组处理
- Prototype - 哈希处理
- Prototype - 基本对象
- Prototype - 模板
- Prototype - 枚举
- Prototype - 事件处理
- Prototype - 表单管理
- Prototype - JSON 支持
- Prototype - AJAX 支持
- Prototype - 表达范围
- Prototype - 定期执行
- Prototype 有用资源
- Prototype - 快速指南
- Prototype - 有用资源
- Prototype - 讨论
Prototype - cumulativeOffset() 方法
此方法返回元素相对于文档左上角的偏移量。
此方法返回一个数组,保持元素的 offsetLeft 和 offsetTop。
请注意所有值都作为数字返回,即使它们以像素表示。
语法
element.cumulativeOffset();
返回值
一个包含两个数字的数组 [offset left, offset top]。
示例
<html>
<head>
<title>Prototype examples</title>
<script type = "text/javascript" src = "/javascript/prototype.js"></script>
<script>
function getOffset() {
var firstElement = $('firstDiv');
var arr = firstElement.cumulativeOffset();
alert ( "Offset Left: " +arr[0]+ " Offset Top : " +arr[0] );
}
</script>
</head>
<body>
<p>Click getOffset button to see the result.</p>
<div id = "firstDiv">
<p>This is first paragraph</p>
</div>
<br />
<input type ="button" value = "getOffset" onclick = "getOffset();"/>
</body>
</html>
输出
prototype_element_object.htm
广告