Skip to content

Commit

Permalink
fix: recursive scrolling
Browse files Browse the repository at this point in the history
  • Loading branch information
X committed Jun 23, 2024
1 parent 5a6346c commit 9ad0fbc
Showing 1 changed file with 7 additions and 0 deletions.
7 changes: 7 additions & 0 deletions src/frontend/src/form.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -892,9 +892,16 @@ const tableTemplate =

const syncScrolling = (elem1: HTMLElement, elem2: HTMLElement) => {
elem1.addEventListener("scroll", () => {
if (elem1.dataset?.scrolling == "0") {
return;
}
const scrollPercentage =
elem1.scrollTop / (elem1.scrollHeight - elem1.clientHeight);
// disable scrolling on the other element to avoid recursion
elem2.setAttribute("data-scrolling", "0");
elem2.scrollTop =
scrollPercentage * (elem2.scrollHeight - elem2.clientHeight);
// enable scrolling again
setTimeout(() => elem2.setAttribute("data-scrolling", "1"), 1000);
});
};

0 comments on commit 9ad0fbc

Please sign in to comment.