Inertia.js and scroll management of scrollable divs #1374
Unanswered
tomoehlrich
asked this question in
Help
Replies: 1 comment
-
I had a similar issue and this is what I did: export const preserveScroll = (selector) => {
const scrollPos = document.querySelector(selector).scrollTop
document.addEventListener(
'inertia:navigate',
() => {
document.querySelector(selector).scrollTop = scrollPos
},
{ once: true }
)
} I add a The function will find the scroll position of the element before something happens, then re-define it to the previous position after inertia navigate event is dispatched. Obs.: You can't store the element in a variable and reuse it inside the callback, or it won't work. |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
I think I may misunderstand scroll management with Inertia.js and scrollable divs. Maybe somebody can point me in the right direction.
I started off without scrollable divs. And using "preserve-scroll" on links works fine and remembers the scroll position in the document body.
Then I switched to a new layout where the height is always 100% of the screen. And the logical columns of the application scroll automatically vertically. Slack-app style.
Clicking on Inertia links with preserve-scroll now does not restore the scroll position of the scrollable elements.
I tried a couple of things like using "scroll-region" but in the documentation it sounds as if scroll-region is not meant for preserving the scroll position but for resetting it.
This is a simplified example of my code (with Vue and Tailwind):
I also tried to add "scroll-region" to the "ul" tag. Using "preserve-state" in the link kind of does the trick but I would like to only preserve the scroll positions of all the scrollable elements after any click.
Any tipps appreciated.
Beta Was this translation helpful? Give feedback.
All reactions