Home > Article > Web Front-end > jQuery method to achieve smooth scrolling to the specified anchor point_jquery
The example in this article describes how jQuery implements smooth scrolling to the specified anchor point. Share it with everyone for your reference. The details are as follows:
Define the specified anchor point and call the following js code to smoothly scroll the page to the specified position. It is very practical, such as returning to the top of the page, going to the bottom of the page, etc.
// HTML: // <h1 id="anchor">Lorem Ipsum</h1> // <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 be helpful to everyone’s jQuery programming.