Programmatically scroll to an Anchor Tag

前端 未结 8 1594
孤独总比滥情好
孤独总比滥情好 2020-11-28 07:21

Consider the following code:

GoTo Label2
... [content here] ...
More content


        
8条回答
  •  慢半拍i
    慢半拍i (楼主)
    2020-11-28 07:37

    This JS has generally worked well for me if you also put an ID on the element:

    document.getElementById('MyID').scrollIntoView(true);
    

    This is good as it will also position scrollable divs etc so that the content is visible.

提交回复
热议问题