Scroll to a specific div

前端 未结 5 710
猫巷女王i
猫巷女王i 2021-01-19 00:44

I have few divs .posts which have a attr data-id which corresponds to the mysql DB id.

5条回答
  •  醉梦人生
    2021-01-19 00:58

    I'm seeing a lot of jQuery and Javascript in here, and simple CSS is here to help!

    html,body {
        scroll-behavior: smooth;
    }
    

    To put this in action, use a link and give it an href with the id of the element you're scrolling to:

    Section One
    
    

    Section One

    Not all browsers however support the scroll-behavior property, in which case I'd recommend the selected answer near the top ;)

提交回复
热议问题