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.