Javascript to make the page jump to a specific location

后端 未结 8 561
悲哀的现实
悲哀的现实 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:37

    If you use jQuery it's pretty simple here is some sample code

    Bellow is the #nav where I stored all the clickable links to the articles in this example

    Note: I used the goto attribute(custom) to pass the ID for the target Article

    
    

    Here, bellow are the Articles you will be jumping to.

    Note: The JavaScript in the last code sample takes the distance of the tag to the top of that page and then scrolls the page down by that same distance measurement taken.

    Sample article Paragraph 1

    Sample article Paragraph 2

    Finally this is the javascript + jQuery that makes it all work, this solution is best when you are working with fixed and layered components.

    
    

    javascript jquery

提交回复
热议问题