JQuery implements smooth scrolling to a specified anchor

Source: Internet
Author: User

JQuery implements smooth scrolling to a specified anchor

This article mainly introduces jQuery's method of smooth scrolling to the specified anchor. The example analyzes jQuery's technique of locating and Rolling Based on anchor. It is very useful. If you need it, you can refer

 

 

This example describes how jQuery implements smooth scrolling to a specified anchor. Share it with you for your reference. The details are as follows:

Define the specified anchor. Calling the following js Code can smoothly scroll the page to the specified position, which is very useful, such as returning to the top of the page and going to the bottom of the page.

?

1

2

3

4

5

6

7

8

9

10

11

12

13

14

// HTML:

// <H1 id = "anchor"> Lorem Ipsum

// <P> <a href = "# anchor" class = "topLink"> Back to Top </a> </p>

$ (Document). ready (function (){

$ ("A. topLink"). click (function (){

$ ("Html, body"). animate ({

ScrollTop: $ (this). attr ("href"). offset (). top + "px"

},{

Duration: 500,

Easing: "swing"

});

Return false;

});

});

I hope this article will help you with jQuery programming.

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.