scroll
English [skrəʊl] American [skroʊl]
n. (Commonly used for recording official documents) paper scroll; scroll, picture scroll, scroll; scroll (decoration);
vt. Make it scroll; (on a computer screen) move from top to bottom (information, etc.), roll pages
vi . (like a scroll) to roll up; (like to unroll a scroll) to display text on the screen
##top
英[tɒp] 美[tɑ:p] n. Top, top; (box) cover, (book pages, etc.) upper column; chief; top adj. The highest; top; first-class; largestvt. Form the top; reach the top of...; be at the forefront of...; leadvi. Summarize; transcend; tower; end
jquery scrollTop() method syntax
Function: scrollTop() method returns or sets the vertical position of the scroll bar of the matching element. scroll top offset refers to the offset of the scroll bar relative to its top. If this method sets no parameters, returns the offset in pixels from the top of the scroll bar.
Syntax: $(selector).scrollTop(offset)
Parameters:
Parameter | Description |
offset | Optional. Specifies the offset, in pixels, from the top of the scroll bar. |
Note: This method is valid for both visible and invisible elements. When used to get a value, this method simply returns the scroll top offset of the first matching element. When used to set a value, this method sets the scroll top offset of all matching elements.
jquery scrollTop() method example
<html> <head> <script type="text/javascript" src="http://apps.bdimg.com/libs/jquery/2.1.1/jquery.min.js"></script> <script type="text/javascript"> $(document).ready(function(){ $(".btn1").click(function(){ $("div").scrollTop(100); }); $(".btn2").click(function(){ alert($("div").scrollTop()+" px"); }); }); </script> </head> <body> <div style="border:1px solid black;width:200px;height:200px;overflow:auto"> This is some text. This is some text. This is some text. This is some text. This is some text. This is some text. This is some text. This is some text. This is some text. This is some text. This is some text. This is some text. This is some text. This is some text. This is some text. This is some text. This is some text. This is some text. This is some text. This is some text. This is some text. This is some text. This is some text. This is some text. This is some text. This is some text. This is some text. This is some text. This is some text. This is some text. This is some text. This is some text. This is some text. This is some text. This is some text. This is some text. </div> <button class="btn1">把 scroll top offset 设置为 100px</button> <br /> <button class="btn2">获得 scroll top offset</button> </body> </html>
Click the "Run instance" button to view the online instance