Skip to content
This repository has been archived by the owner on Mar 15, 2018. It is now read-only.

Commit

Permalink
Improve scroll restoration perf (bug 986625)
Browse files Browse the repository at this point in the history
  • Loading branch information
muffinresearch committed Mar 26, 2014
1 parent e0d45e1 commit 429071e
Showing 1 changed file with 9 additions and 18 deletions.
27 changes: 9 additions & 18 deletions hearth/media/js/navigation.js
Expand Up @@ -10,7 +10,6 @@ define('navigation',
{path: '/', type: 'root'}
];
var initialized = false;
var scrollTimer;

function extract_nav_url(url) {
// This function returns the URL that we should use for navigation.
Expand Down Expand Up @@ -60,26 +59,18 @@ define('navigation',

var top = 0;
if ((state.preserveScroll || popped) && state.scrollTop) {
if (state.docHeight) {
// Preserve document min-height for scroll restoration.
z.body.css('min-height', state.docHeight);
z.page.one('loaded', function() {
// Remove specified min-height.
z.body.css('min-height', '');
});
}
// Preserve document min-height for scroll preservation
// (e.g. when scroll pos should not change).
z.body.css('min-height', state.docHeight);
z.page.one('loaded', function() {
// Remove specified min-height.
z.body.css('min-height', '');
});
top = state.scrollTop;
}

// Introduce small delay to ensure content
// is ready to scroll. (Bug 976466)
if (scrollTimer) {
window.clearTimeout(scrollTimer);
}
scrollTimer = window.setTimeout(function() {
console.log('Setting scroll to', top);
window.scrollTo(0, top);
}, 250);
console.log('Setting scroll immediately to ', top);
window.scrollTo(0, top);

// Clean the path's parameters.
// /foo/bar?foo=bar&q=blah -> /foo/bar?q=blah
Expand Down

0 comments on commit 429071e

Please sign in to comment.