How to handle scroll position on hashchange in Backbone.js application?

前端 未结 4 728
悲哀的现实
悲哀的现实 2021-02-01 17:05

I\'ve read through many related threads but none of them seem to provide a solution.

What I\'m trying to do is handle the scrollbar intelligently in my Backbone.js app.

4条回答
  •  情话喂你
    2021-02-01 17:39

    A simple solution: Store the position of the list view on every scroll event in a variable:

    var pos;
    $(window).scroll(function() {
        pos = window.pageYOffset;
    });
    

    When returning from the item view, scroll the list view to the stored position:

    window.scrollTo(0, pos);
    

提交回复
热议问题