mirror of https://github.com/fantasticit/think.git
client: fix tocs scroll listener
This commit is contained in:
parent
c20c9794f9
commit
1b2843f185
|
@ -3,7 +3,7 @@ export function throttle(func, wait, options?: { leading: boolean; trailing: boo
|
|||
let timeout = null;
|
||||
let previous = 0;
|
||||
|
||||
if (!options) options = { leading: true, trailing: true };
|
||||
if (!options) options = { leading: false, trailing: true };
|
||||
|
||||
const later = function () {
|
||||
previous = options.leading === false ? 0 : Date.now();
|
||||
|
|
|
@ -69,11 +69,13 @@ export const Tocs: React.FC<{ editor: Editor; getContainer: () => HTMLElement }>
|
|||
const container = $container.current;
|
||||
if (!container) return;
|
||||
|
||||
const activeAnchor = container.querySelector('.semi-anchor-link-title-active');
|
||||
if (!activeAnchor) return;
|
||||
|
||||
scrollIntoView(activeAnchor, { behavior: 'smooth', scrollMode: 'if-needed' });
|
||||
}, 200);
|
||||
let target = container.querySelector('.semi-anchor-link-title-active');
|
||||
if (!target) {
|
||||
target = container.querySelector('.semi-anchor-link-title:first-of-type');
|
||||
}
|
||||
if (!target) return;
|
||||
scrollIntoView(target, { scrollMode: 'if-needed' });
|
||||
}, 100);
|
||||
|
||||
el.addEventListener('scroll', scrollHandler);
|
||||
|
||||
|
|
Loading…
Reference in New Issue