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