Copyright © tutorialspoint.com

Prototype viewportOffset() Method

previous next


Advertisements

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:

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>

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


previous next

Copyright © tutorialspoint.com