Scroll to a specific Element Using html

前端 未结 10 1353
猫巷女王i
猫巷女王i 2020-12-02 12:09

Is there a method in html which makes the webpage scroll to a specific Element using HTML !?

10条回答
  •  遥遥无期
    2020-12-02 12:45

    The above answers are good and correct. However, the code may not give the expected results. Allow me to add something to explain why this is very important.

    It is true that adding the scroll-behavior: smooth to the html element allows smooth scrolling for the whole page. However not all web browsers support smooth scrolling using HTML.

    So if you want to create a website accessible to all user, regardless of their web browsers, it is highly recommended to use JavaScript or a JavaScript library such as jQuery, to create a solution that will work for all browsers.

    Otherwise, some users may not enjoy the smooth scrolling of your website / platform.

    I can give a simpler example on how it can be applicable.

    
    
    
    
    
    
    
    

    Smooth Scroll

    Section 1

    Click on the link to see the "smooth" scrolling effect.

    Click Me to Smooth Scroll to Section 2 Below

    Note: Remove the scroll-behavior property to remove smooth scrolling.

提交回复
热议问题