Home >Web Front-end >JS Tutorial >jQuery Auto Scroll To Top Of Page

jQuery Auto Scroll To Top Of Page

Christopher Nolan
Christopher NolanOriginal
2025-03-11 00:06:11962browse

Use jQuery for Smooth, Automated Scrolling to the Top

This simple jQuery code snippet provides a smooth, automated scroll to the top of your webpage. Why use it? It saves users time scrolling on long pages and adds a visually appealing touch.

[Live Demo: jQuery Scroll to Top](Link to Demo - Replace with actual demo link if available)

Here's the code:

jQuery(document).ready(function($) {
    $('a[href=#topbar]').click(function(){
        $('html, body').animate({scrollTop:0}, 'slow');
        return false;
    });
});

Frequently Asked Questions (FAQs)

How do I implement this on my website?

  1. Include the jQuery library in your HTML (download from jQuery.com or use a CDN).
  2. Add the above code snippet within <script></script> tags, ideally just before the closing

The above is the detailed content of jQuery Auto Scroll To Top Of Page. For more information, please follow other related articles on the PHP Chinese website!

Statement:
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