I'm a newbie to javascript, so please forgive if I ask things that are painfully obvious.
I am using Sennajs for my personal project. I have a issue like in gallery example. When click a link, it makes the page jump to the top. I used to use this code from jquery to fix it. However it also prevents senna from working.
$('a').click(function(e) {
// do something
return false;
e.preventDefault();
});
Any help would be very appreciated.
It turns out that you can use
app.setUpdateScrollPosition(false)
to avoid jumping to the top of the page after every SennaJS navigation: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:
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).