Copyright ©

Prototype cumulativeScrollOffset() Method

previous next


This method calculates and returns the cumulative scroll offset of an element in nested scrolling containers. This adds the cumulative scrollLeft and scrollTop of an element and all its parents.

This is used for calculating the scroll offset of an element that is in more than one scroll container (e.g., a draggable in a scrolling container which is itself part of a scrolling document).

This method return an array keeping offsetLeft and offsetTop of the element.



Return Value:


<title>Prototype examples</title>
<script type="text/javascript" 

function getOffset(){
   firstElement = $('firstDiv');
   var arr = firstElement.cumulativeScrollOffset();
   alert ( "Offset Left: " +arr[0]+ " Offset Top : " +arr[0]);



   <p>Click getOffset button to see the result.</p>
   <div id="firstDiv">
      <p>This is first paragraph</p> 

   <br />
   <input type="button" value="getOffset" 


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

previous next

Copyright ©