Home > Web Front-end > JS Tutorial > body text

jQuery method to achieve smooth scrolling to the specified anchor point_jquery

WBOY
Release: 2016-05-16 16:08:19
Original
1375 people have browsed it

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;
  });
});
Copy after login

I hope this article will be helpful to everyone’s jQuery programming.

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template