Tutorials Point


  Learn Prototype
  Prototype Resources
  Selected Reading

Copyright © 2014 by tutorialspoint



  Home     References     Discussion Forums     About TP  

Prototype viewportOffset() Method


previous next AddThis Social Bookmark Button


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:

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

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



previous next Printer Friendly

Advertisements


  

Advertisements