jquery animation effects animate and ScrollTop combined with instances _jquery

Source: Internet
Author: User

CSS property values are gradually changed, so you can create animation effects.
Only numeric values can create animations (such as "margin:30px").
String values cannot create animations (such as "background-color:red").

Copy Code code as follows:
$ (' #shang '). Click (function () {$ (' html,body '). Animate ({scrolltop: ' 0px '}, 800);});

The code above indicates that the scroll bar jumps to 0, and the page moves at 800.
Combined with scrolltop Practical example:
Copy Code code as follows:

JQuery (document). Ready (function ($) {
$ (' #shang '). Click (function () {
$ (' html,body '). Animate ({scrolltop: ' 0px '}, 800);
});
$ (' #comt '). Click (function () {
$ (' html,body '). Animate ({scrolltop:$ (' #comments '). Offset (). Top}, 800);
});
$ (' #xia '). Click (function () {
$ (' html,body '). Animate ({scrolltop:$ (' #footer '). Offset (). Top}, 800);
});
});

To move to a specified location by clicking on the correlation ID:
Click the element with ID Shang and return to the top;
Click on the element with ID COMT and return to the location with ID comments;
Click on the element with ID Xia and return to the bottom;

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.