Skip to content

Commit 28ed396

Browse files
fix: scroll lagging on pages with TOC and large number of headers (#148)
reduces the number of TOC refreshes by throttling calls to the DoxygenAwesomeInteractiveToc.update() method. Fixes #147 Co-authored-by: jothepro <github@jothe.pro>
1 parent 00c7339 commit 28ed396

File tree

2 files changed

+28
-4
lines changed

2 files changed

+28
-4
lines changed

doxygen-awesome-interactive-toc.js

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -55,9 +55,7 @@ class DoxygenAwesomeInteractiveToc {
5555
headerNode: document.getElementById(id)
5656
})
5757

58-
document.getElementById("doc-content")?.addEventListener("scroll", () => {
59-
DoxygenAwesomeInteractiveToc.update()
60-
})
58+
document.getElementById("doc-content")?.addEventListener("scroll",this.throttle(DoxygenAwesomeInteractiveToc.update, 100))
6159
})
6260
DoxygenAwesomeInteractiveToc.update()
6361
}
@@ -78,4 +76,16 @@ class DoxygenAwesomeInteractiveToc {
7876
active?.classList.add("active")
7977
active?.classList.remove("aboveActive")
8078
}
81-
}
79+
80+
static throttle(func, delay) {
81+
let lastCall = 0;
82+
return function (...args) {
83+
const now = new Date().getTime();
84+
if (now - lastCall < delay) {
85+
return;
86+
}
87+
lastCall = now;
88+
return setTimeout(() => {func(...args)}, delay);
89+
};
90+
}
91+
}

package-lock.json

Lines changed: 14 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)