Copyright © tutorialspoint.com

Prototype positionedOffset() Method

previous next


Advertisements

This method returns element.s offset relative to its closest positioned ancestor. This calculates the cumulative offsetLeft and offsetTop of an element and all its parents until it reaches an element with a position of static.

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

Syntax:

element.positionedOffset();

Return Value:

Example:

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

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


previous next

Copyright © tutorialspoint.com