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

前端 未结 4 730
悲哀的现实
悲哀的现实 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:32

    @Mirage114 Thanks for posting your solution. It works like a charm. Just a minor thing, it assumes the route functions are synchronous. If there is an async operation, for example fetching remote data before rendering a view, then window is scrolled before the view content is added to the DOM. In my case, I cache data when a route is visited for the first time. This is so that when a user hits browser back/forward button, the async operation of fetching data is avoided. However it might not always be possible to cache every data you need for a route.

提交回复
热议问题