- Prototype Tutorial
- Prototype - Home
- Prototype - Short Overview
- Prototype - Useful Features
- Prototype - Utility Methods
- Prototype - Element Object
- Prototype - Number Processing
- Prototype - Strings Processing
- Prototype - Array Processing
- Prototype - Hash processing
- Prototype - Basic Object
- Prototype - Templating
- Prototype - Enumerating
- Prototype - Event Handling
- Prototype - Form Management
- Prototype - JSON Support
- Prototype - AJAX Support
- Prototype - Expressing Ranges
- Prototype - Periodical Execution
- Prototype Useful Resources
- Prototype - Quick Guide
- Prototype - Useful Resources
- Prototype - Discussion
Prototype - positionedOffset() Method
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
Returns element.s offset relative to its closest positioned ancestor.
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>
Output
prototype_element_object.htm
Advertisements