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 timeout = null;
|
||||||
let previous = 0;
|
let previous = 0;
|
||||||
|
|
||||||
if (!options) options = { leading: true, trailing: true };
|
if (!options) options = { leading: false, trailing: true };
|
||||||
|
|
||||||
const later = function () {
|
const later = function () {
|
||||||
previous = options.leading === false ? 0 : Date.now();
|
previous = options.leading === false ? 0 : Date.now();
|
||||||
|
|
|
@ -69,11 +69,13 @@ export const Tocs: React.FC<{ editor: Editor; getContainer: () => HTMLElement }>
|
||||||
const container = $container.current;
|
const container = $container.current;
|
||||||
if (!container) return;
|
if (!container) return;
|
||||||
|
|
||||||
const activeAnchor = container.querySelector('.semi-anchor-link-title-active');
|
let target = container.querySelector('.semi-anchor-link-title-active');
|
||||||
if (!activeAnchor) return;
|
if (!target) {
|
||||||
|
target = container.querySelector('.semi-anchor-link-title:first-of-type');
|
||||||
scrollIntoView(activeAnchor, { behavior: 'smooth', scrollMode: 'if-needed' });
|
}
|
||||||
}, 200);
|
if (!target) return;
|
||||||
|
scrollIntoView(target, { scrollMode: 'if-needed' });
|
||||||
|
}, 100);
|
||||||
|
|
||||||
el.addEventListener('scroll', scrollHandler);
|
el.addEventListener('scroll', scrollHandler);
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue