docs: improve anchor scrolling

This commit is contained in:
陈嘉涵
2020-01-04 20:10:29 +08:00
parent bbaa9859be
commit 04f67f16bc
7 changed files with 37 additions and 25 deletions
+19
View File
@@ -0,0 +1,19 @@
export function scrollToAnchor(selector) {
let count = 0;
const timer = setInterval(() => {
const el = document.querySelector(selector);
if (el) {
el.scrollIntoView({
behavior: 'smooth'
});
clearInterval(timer);
} else {
count++;
if (count > 10) {
clearInterval(timer);
}
}
}, 100);
}