Saturday, 31 August 2013

Backbone: Scroll event not firing after back button is pressed

Backbone: Scroll event not firing after back button is pressed

As you can see here, when you click on an image and then click back,
Chrome doesn't let you scroll down anymore. I'm using the following
function to change the primary view of my Backbone application:
changeView: function(view, options) {
if (this.contentView) {
this.contentView.undelegateEvents();
this.contentView.stopListening();
this.contentView = null;
}
this.contentView = view;
if (!options || (options && !options.noScroll)) {
$(document).scrollTop(0);
}
this.contentView.render();
},
This function is called every time the route changes. As you can see, I'm
resetting the scroll position every time the primary view changes (so that
the user doesn't land on the middle of a view after scrolling down on the
previous view). However, when the user presses the back button, the scroll
event isn't firing at all if you try to scroll down. If you try to scroll
up, however, then the scroll positions seems to get reset to a position
further down the page, after which scrolling works normally.
Any ideas on what the cause might be?

No comments:

Post a Comment