- 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 - viewportOffset() Method
This method returns the X/Y coordinates of element relative to the viewport. Returned positions will be absolute.
NOTE − All values are returned as numbers, only although they are expressed in pixels.
Syntax
element.viewportOffset();
Return Value
An array of numbers [Left, Top].
Example
<html> <head> <title>Prototype examples</title> <script type = "text/javascript" src = "/javascript/prototype.js"></script> <script> function showResult() { var coordinates = $('visible').viewportOffset(); alert("Distance from the Left : " + coordinates[0] ); alert("Distance from the Top : " + coordinates[1] ); } </script> </head> <body> <div id = "visible" style = "position:absolute;left:50px; top:50px;"> This is visible division 50 pixels down from the top. </div> <input type = "button" value = "Click" onclick = "showResult();"/> </body> </html>
Output
prototype_element_object.htm
Advertisements