How do I maintain scroll position in MVC?

后端 未结 12 1920
情歌与酒
情歌与酒 2020-11-27 18:02

Im working on a project in MVC and have enjoyed learning about it. There are a few growing pains but once you figure them out it\'s not bad. One thing that is really simpl

12条回答
  •  野趣味
    野趣味 (楼主)
    2020-11-27 18:38

    I've resolved this in JS :

    $(document).scroll(function(){
        localStorage['page'] = document.URL;
        localStorage['scrollTop'] = $(document).scrollTop();
    });
    

    Then in document ready :

    $(document).ready(function(){
        if (localStorage['page'] == document.URL) {
            $(document).scrollTop(localStorage['scrollTop']);
        }
    });
    

提交回复
热议问题