Created
February 11, 2016 00:10
-
-
Save mondaychen/352a1d80e6f681d7dc90 to your computer and use it in GitHub Desktop.
Page Scroll Workaround for Single-Page Apps
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var $container = $('#container'); | |
... | |
// when some route is matched | |
var view = new AnotherPage(); | |
$container.html(view.render().el); | |
window.scrollTo(0, 0); | |
$container.html(el) | |
// jump to top if needed | |
if(historyManager.isUserJump(Backbone.history.fragment)) { | |
window.scrollTo(0, 0) | |
} | |
// make body long enough to help browser jump to the right position | |
$body.css('min-height', '99999px') | |
// set dom | |
$container.html(el) | |
// jump to top if needed | |
if(historyManager.isUserJump(Backbone.history.fragment)) { | |
window.scrollTo(0, 0) | |
} | |
// after 0.1s set min-height to a normal value | |
// hopefully no one will notice that | |
_.delay(function() { | |
$body.css('min-height', '450px') | |
}, 100) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment