Prototype cumulativeOffset() Method


Advertisements


This method returns the offsets of element from the top left corner of the document.

This method returns an array keeping offsetLeft and offsetTop of the element.

Note that all values are returned as numbers, only although they are expressed in pixels.

Syntax

element.cumulativeOffset();

Return Value

  • An array of two numbers [offset left, offset top].

Example

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

To understand it in better way you can Try it yourself.


prototype_element_object.htm

Advertisements