Javascript to make the page jump to a specific location

后端 未结 8 551
悲哀的现实
悲哀的现实 2020-12-13 15:09

I there a way in javascript to make the page jump to a specific location on the page, such as


         


        
8条回答
  •  孤城傲影
    2020-12-13 15:42

    2020 Answer

    A simple and modern way to do this would be like this:

    document.getElementById("jump_to_this_location").scrollIntoView({behavior: 'smooth'});
    

    The behaviour: 'smooth' argument makes the jump... well... smooth. Which is something probably most of you want.

提交回复
热议问题