mirror of
https://gitee.com/vant-contrib/vant.git
synced 2025-04-06 03:57:59 +08:00
18 lines
331 B
JavaScript
18 lines
331 B
JavaScript
export function scrollToAnchor(selector) {
|
|
let count = 0;
|
|
|
|
const timer = setInterval(() => {
|
|
const el = document.querySelector('#' + selector);
|
|
if (el) {
|
|
el.scrollIntoView();
|
|
clearInterval(timer);
|
|
} else {
|
|
count++;
|
|
|
|
if (count > 10) {
|
|
clearInterval(timer);
|
|
}
|
|
}
|
|
}, 100);
|
|
}
|