- 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 - cumulativeScrollOffset() Method
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 returns an array keeping offsetLeft and offsetTop of the element.
Syntax
element.cumulativeScrollOffset();
Return Value
An array of two numbers [offset let, offset top].
Example
<html> <head> <title>Prototype examples</title> <script type = "text/javascript" src = "/javascript/prototype.js"></script> <script> function getOffset() { firstElement = $('firstDiv'); var arr = firstElement.cumulativeScrollOffset(); alert ( "Offset Left: " +arr[0]+ " Offset Top : " +arr[0]); } </script> </head> <body> <p>Click getOffset button to see the result.</p> <div id = "firstDiv"> <p>This is first paragraph</p> </div> <br /> <input type = "button" value = "getOffset" onclick = "getOffset();"/> </body> </html>
Output
prototype_element_object.htm
Advertisements