This commit is contained in:
Bjørn Erik Pedersen 2025-02-13 10:40:34 +01:00
commit 304a7e5e74
No known key found for this signature in database
817 changed files with 5301 additions and 14766 deletions

View file

@ -0,0 +1,17 @@
export const scrollToActive = (when) => {
let els = document.querySelectorAll('.scroll-active');
if (!els.length) {
return;
}
els.forEach((el) => {
// Find scrolling container.
let container = el.closest('[data-turbo-preserve-scroll-container]');
if (container) {
// Avoid scrolling if el is already in view.
if (el.offsetTop >= container.scrollTop && el.offsetTop <= container.scrollTop + container.clientHeight) {
return;
}
container.scrollTop = el.offsetTop - container.offsetTop;
}
});
};