Home > Web Front-end > JS Tutorial > How Can I Programmatically Scroll to the Bottom of a Web Page Using JavaScript?

How Can I Programmatically Scroll to the Bottom of a Web Page Using JavaScript?

DDD
Release: 2024-12-02 20:11:11
Original
1067 people have browsed it

How Can I Programmatically Scroll to the Bottom of a Web Page Using JavaScript?

Scroll to Bottom of Page Automatically

Looking to scroll to a specific element at the bottom of a page upon clicking a certain trigger? This can be achieved effectively without utilizing jQuery.

Solution:

window.scrollTo(0, document.body.scrollHeight);
Copy after login

Explanation:

This simple JavaScript code will scroll the page vertically to the position specified by the document.body.scrollHeight property. It represents the total height of the document's body, including any vertically scrolled elements.

Considerations:

  • In the case of nested elements, you may need to target the element that scrolls and use its scroll height instead:

    nestedElement.scrollTo(0, nestedElement.scrollHeight);
    Copy after login

Additional Resources:

  • http://www.alecjacobson.com/weblog/?p=753
  • http://www.mediacollege.com/internet/javascript/page/scroll.html
  • http://www.electrictoolbox.com/jquery-scroll-bottom/

The above is the detailed content of How Can I Programmatically Scroll to the Bottom of a Web Page Using JavaScript?. For more information, please follow other related articles on the PHP Chinese website!

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