- 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
廣告