返回到:Prototype – 元素对象
此方法返回元素距文档左上角的偏移量。
此方法返回一个数组,保留元素的 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 – 元素对象