How to prevent scrolling on prepend?

后端 未结 4 1853
广开言路
广开言路 2021-01-30 13:45

I\'m prepending content to the top of the body. Sometimes this content can be 400-500px tall, and when something like this gets added, pushing the content down when you are read

4条回答
  •  予麋鹿
    予麋鹿 (楼主)
    2021-01-30 13:58

    I know, I'm very late to that topic. Sorry for undigging it, but I discovered a very simple way for preventing scrolling to top when you prepend elements to the body.

    The auto-scrolling appends when the scroll Y-position is at zero. Simply do this :

    element.scrollTo(0, 1);
    

    And your element won't automatically go to the top after the prepend.

提交回复
热议问题