How to scroll HTML page to given anchor?

后端 未结 17 2039
醉梦人生
醉梦人生 2020-11-22 08:55

I’d like to make the browser to scroll the page to a given anchor, just by using JavaScript.

I have specified a name or id attribute in my

17条回答
  •  旧巷少年郎
    2020-11-22 08:59

    Most answers are unnecessarily complicated.

    If you just want to jump to the target element, you don't need JavaScript:

    # the link:
    Click here to jump.
    
    # target element:
    
    Any kind of element.

    If you want to scroll to the target animatedly, please refer to @Shahil's answer.

提交回复
热议问题