jquery jump to the top and bottom animation 2-sentence code simple to achieve

Source: Internet
Author: User
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>

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.