Scrollbar top

.scrollTop[]Returns: Number

Description: Get the current vertical position of the scroll bar for the first element in the set of matched elements or set the vertical position of the scroll bar for every matched element.

  • version added: 1.2.6.scrollTop[]

    • This method does not accept any arguments.

The vertical scroll position is the same as the number of pixels that are hidden from view above the scrollable area. If the scroll bar is at the very top, or if the element is not scrollable, this number will be 0.

Example:

Get the scrollTop of a paragraph.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
scrollTop demo
p {
margin: 10px;
padding: 5px;
border: 2px solid #666;
}
Hello
var p = $[ "p" ].first[];
$[ "p" ].last[].text[ "scrollTop:" + p.scrollTop[] ];

Demo:

.scrollTop[ value ]Returns: jQuery

Description: Set the current vertical position of the scroll bar for each of the set of matched elements.

  • version added: 1.2.6.scrollTop[ value ]

    • value
      Type: Number
      A number indicating the new position to set the scroll bar to.

The vertical scroll position is the same as the number of pixels that are hidden from view above the scrollable area. Setting the scrollTop positions the vertical scroll of each matched element.

Example:

Set the scrollTop of a div.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
scrollTop demo
div.demo {
background: #ccc none repeat scroll 0 0;
border: 3px solid #666;
margin: 5px;
padding: 5px;
position: relative;
width: 200px;
height: 100px;
overflow: auto;
}
p {
margin: 10px;
padding: 5px;
border: 2px solid #666;
width: 1000px;
height: 1000px;
}
lalalaHello
$[ "div.demo" ].scrollTop[ 300 ];

Demo:

Video liên quan

Chủ Đề