Use 2 code simple to achieve jquery animation jump to the top and bottom; When the top button is clicked, the execution method, ScrollTop property gets the distance of the selected label from the scroll bar, the specific implementation is as follows, interested friends can refer to the following
copy code The code is as follows:
<! DOCTYPE HTML PUBLIC "-//W3C//DTD XHTML 1.0 transitional//en" "Http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd ">
<title>untitled page</ title>
<script type= "Text/javascript" src=jquery-1.8.0.js></script>
<script>
$ ( Document). Ready (function () {
///when clicking on the top button, execute method, ScrollTop property gets the distance of the selected label from the scroll bar.
$ (' #top '). Click (function () {
$ (' html '). Animate (
{scrolltop: ' 0px '}, 1000
);
});
//When the bottom tab is clicked, the method is executed, in which offset () Gets the relative offset of the matching element at the current viewport, returns an object with two attributes Top,left
//animate, the second attribute of course we can also set ' slow ', ' Normal ' or ' fast '
$ (' #foot '). Click (function () {
$ (' html '). Animate (
{scrolltop:$ (' span '). Offset (). Top}, 1000
);
});
});
</script>
<body>
<br/> <br/> <br/> <br/> <br />
<a href= "#" id= "foot" > Bottom </a>
<br/> <br /> <br /> <br /> <br />
<br /> <br /> <br /> <br /> <br />
<a href= "#" id= "Top" > </a>
<br/> <br/> <br/> <br/> <br/>
& Lt;span></span>
</body>