How to make a button scroll down page in HTML?

后端 未结 2 1212
太阳男子
太阳男子 2021-02-13 20:52

Couldn\'t find a tutorial for this anywhere or just didn\'t use the right keywords. I\'m making a one-paged website, and I\'d like the navigation bar buttons to scroll the page

相关标签:
2条回答
  • 2021-02-13 21:35

    Update: There is now a better way to use this, using the HTML id attribute:

    Set the destination id: <h1 id="section1">Section 1</h1>

    And create a link to that destination using the anchor tag: <a href="#section1">Go to section 1</a>

    The benefit of this new method is that the id attribute can be set on any HTML element. You don't have to wrap superfluous anchor tags around destination links anymore!

    Original answer:

    You can look at using the HTML anchor tag.

    <a name="section1">Section 1</a>

    alongside

    <a href="#section1">Go to section 1</a>

    When the user clicks on "Go to section 1", they will be sent to the section of the page where the "Section 1" text is displayed.

    0 讨论(0)
  • 2021-02-13 21:37

    using window.scrollTo you can scroll down your page like this

    window.scrollTo(0,document.body.scrollHeight);
    
    0 讨论(0)
提交回复
热议问题