- 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 - cumulativeScrollOffset() 方法
此方法計算並返回巢狀滾動容器中的元素的累積滾動偏移。這會累加元素及其所有父元素的 scrollLeft 和 scrollTop。
這用於計算處於多個滾動容器中(例如,滾動容器中的可拖動元素,本身也是滾動文件的一部分)的元素的滾動偏移。
此方法返回一個保留元素的 offsetLeft 和 offsetTop 的陣列。
語法
element.cumulativeScrollOffset();
返回值
包含兩個數字 [offset left, offset top] 的陣列。
示例
<html>
<head>
<title>Prototype examples</title>
<script type = "text/javascript" src = "/javascript/prototype.js"></script>
<script>
function getOffset() {
firstElement = $('firstDiv');
var arr = firstElement.cumulativeScrollOffset();
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
廣告