It turns out that you can use app.setUpdateScrollPosition(false)
to avoid jumping to the top of the page after every SennaJS navigation:
var app = new senna.App();
app.setUpdateScrollPosition(false);
// ...your code here...
Old Solution (Not Recommended):
Note: this solution is unnecessarily overcomplicated since I wrote it before I knew about app.setUpdateScrollPosition(false)
.
Instead of preventing SennaJS from executing, you could save the current scroll position before navigating and scroll to the correct position after navigating:
var app = new senna.App();
// ...your code here...
function getScrollTop() {
// Taken from Engineer's answer:
// https://stackoverflow.com/questions/11193453/find-the-vertical-position-of-scrollbar-without-jquery#11193613
return (window.pageYOffset !== undefined) ? window.pageYOffset :
(document.documentElement || document.body.parentNode || document.body).scrollTop;
}
var scrollTop = getScrollTop();
app.on('beforeNavigate', function(event) {
scrollTop = getScrollTop();
});
app.on('endNavigate', function(event) {
window.scrollTo(0, scrollTop);
});
For more information about scroll positions and JavaScript, see Engineer's answer here and MDN's window.scrollTo()
documentation.
For more information about SennaJS Lifecycle Events, see the SennaJS documentation
Note: this may be a bug in SennaJS, so I've created a bug report (#184).