How to get and set the current web page scroll position?

前端 未结 4 1114
无人共我
无人共我 2020-12-02 06:38

How can I get and set the current web page scroll position?

I have a long form which needs to be refreshed based on user actions/input. When this happens, the page

4条回答
  •  佛祖请我去吃肉
    2020-12-02 06:58

    I went with the HTML5 local storage solution... All my links call a function which sets this before changing window.location:

    localStorage.topper = document.body.scrollTop;
    

    and each page has this in the body's onLoad:

      if(localStorage.topper > 0){ 
        window.scrollTo(0,localStorage.topper);
      }
    

提交回复
热议问题