Language References
Sets or retrieves the distance between the top edge of the object and the topmost portion of the object that is currently visible in the window.
HTML |
N/A |
Script |
object.scrollTop [ = iDistance ] |
iDistance |
Integer value representing the distance, in pixels. |
The property is read/write with a default value of 0.
The property's value is equal to the vertical distance that the content of the object has been scrolled. Although the value can be set to any positive or negative value, if the assigned value is less than zero, the property is set to zero. If the assigned value is greater than the maximum possible, the property is set to the maximum possible.
This property can be set inline but the results may not be consistent while the page is loading.
This property is always zero for objects that do not have scroll bars. For these objects, setting the property has no effect.
When a MARQUEE object is scrolling horizontally its scrollTop property is set to zero, overriding any script setting.
For more information on how to access the dimension and location of elements on the page through the document object model, see Measuring Element Dimension and Location.
The following example shows how the scrollTop property can be used to determine the amount of scrolling done by an object.
<div style="width:300px; height:150px;
overflow:scroll"
onclick="alert ( this.scrollTop )">
<span style="width:350px;background:maroon">
The text in this box ... </span></div>
This feature requires Microsoft® Internet Explorer® 4.0 or later.
Show me
scrollHeight, scrollLeft, scrollWidth