mirror of
https://github.com/codex-team/codex.docs.git
synced 2025-08-07 14:35:26 +02:00
Update table-of-content.js
This commit is contained in:
parent
4ff756e1d0
commit
c740b97a26
1 changed files with 11 additions and 14 deletions
|
@ -93,7 +93,14 @@ export default class TableOfContent {
|
|||
* Watch active section while scrolling
|
||||
*/
|
||||
watchActiveSection() {
|
||||
const detectSection = (scrollPosition) => {
|
||||
const detectSection = () => {
|
||||
/**
|
||||
* Calculate scroll position
|
||||
*
|
||||
* @todo research how not to use magic number
|
||||
*/
|
||||
let scrollPosition = this.getScrollPadding() + window.scrollY + 1;
|
||||
|
||||
/**
|
||||
* Find the nearest section above the scroll position
|
||||
*/
|
||||
|
@ -119,24 +126,14 @@ export default class TableOfContent {
|
|||
/**
|
||||
* Define a flag to reduce number of calls to detectSection function
|
||||
*/
|
||||
const throttledDetectSectionFunction = Decorators.throttle((lastKnownScrollPosition) => {
|
||||
detectSection(lastKnownScrollPosition);
|
||||
const throttledDetectSectionFunction = Decorators.throttle(() => {
|
||||
detectSection();
|
||||
}, 200);
|
||||
|
||||
/**
|
||||
* Scroll listener
|
||||
*/
|
||||
document.addEventListener('scroll', (event) => {
|
||||
/**
|
||||
* Calculate scroll position
|
||||
*/
|
||||
let lastKnownScrollPosition = this.getScrollPadding() + window.scrollY + 1;
|
||||
|
||||
/**
|
||||
* Call section detecting function
|
||||
*/
|
||||
throttledDetectSectionFunction(lastKnownScrollPosition);
|
||||
});
|
||||
document.addEventListener('scroll', throttledDetectSectionFunction);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue