10 out of 20 rated this helpful - Rate this topic

scrollTop property

[This documentation is preliminary and is subject to change.]

Sets or retrieves the distance between the top of the object and the topmost portion of the content currently visible in the window.

Syntax

JavaScript

p = object.scrollTop

Property values

Type: Integer

the distance, in pixels.

0

ValueCondition

 

Remarks

This property's value equals the current vertical offset of the content within the scrollable range. Although you can set this property to any value, if you assign a value less than 0, the property is set to 0. If you assign a value greater than the maximum value, the property is set to the maximum value.

You can set this property inline, but the results might be inconsistent while the document is loading.

This property is always 0 for objects that do not have scroll bars. For these objects, setting the property has no effect.

When a marquee object scrolls horizontally, its scrollTop property is set to 0, overriding any script setting.

For more information about how to access the dimension and location of elements on the document through the Dynamic HTML (DHTML) Object Model, see Measuring Element Dimension and Location with CSSOM in Internet Explorer 9.

Examples

This example uses the scrollTop property to determine the amount scrolled by the object.

Code example: http://samples.msdn.microsoft.com/workshop/samples/author/dhtml/refs/scrollTop.htm


<div id="oDiv" style="position: absolute; 
    width: 200px; 
    height: 100px; 
    overflow: scroll" 
    onclick="alert(this.scrollTop)">
	<span style="width: 250px">. . . </span>
</div>

See also

a
address
applet
b
bdo
big
blockQuote
body
button
caption
center
cite
code
col
colGroup
custom
dd
dfn
dir
div
dl
dt
em
embed
fieldSet
form
head
hn
html
i
img
input type=button
input type=checkbox
input type=file
input type=image
input type=password
input type=radio
input type=reset
input type=submit
input type=text
isIndex
kbd
label
legend
li
listing
marquee
menu
meta
noBR
object
ol
option
p
plainText
pre
s
samp
script
select
small
span
strike
strong
sub
sup
table
tBody
td
textArea
tFoot
th
tHead
tr
tt
u
ul
var
xmp
Reference
scrollHeight
scrollLeft
scrollWidth

 

 

Build date: 3/8/2012

Did you find this helpful?
(1500 characters remaining)
Community Content Add
Annotations FAQ
scrollTop doesn't work either in getting or setting values for &lt;SELECT&gt; element
Although this property exists before IE5.5, I just found that it doesn't work in IE6. If you want to get the scrollTop value of a multiple <SELECT> element, it always returns 0. If you want to set it to some value to make the <SELECT> scroll, it doesn't respond.