Open jtokoph opened 8 years ago
I should mention that my current workaround is to listen to page:before-unload
and save scroll positions. Then on page:update
restoring those scroll positions. Would be nice if I didn't have to do that for each scroll view though.
I've been trying for the last 2 days to try and get turbolinks to persist elements. What's the secret? Elements I annotate with the data-turbolinks-permanent
are not persisting. I copied your html and when I clicked on a link, it disappeared, even though the network tab shows it was loaded via turbolinks. I've tried v3 and v5 to no avail.
this will work if you don't want to worry about permanent
var scrollLeft = 0;
//restore the menu position
$(document).on('page:change', function() {
$('.menu').scrollLeft(scrollLeft);
});
//before the current page goes away, save the menu position
$(document).on('page:before-unload', function() {
scrollLeft = $('.menu').scrollLeft();
});
Elements with
data-turbolinks-permanent
and a style ofoverflow: scroll
are losing scroll position when navigation/replacement occurs.Example html that can be dropped into any turbolinks page.
You'll see that the content is properly preserved, but the scroll position is not.
This could be a reason to bring back something like #583. My use case would work if I could do something like this:
I have a chat widget on the page that should maintain it's scroll position to the bottom where the latest messages are.