/
githubmirror
/
tabler
Обзор
Документация
Войти
/
githubmirror
/
tabler
Код
Запросы
0
Пакеты
0
Релизы
0
Аналитика
Безопасность
dev
core/js/src/countup.ts
33 строки
1 KB
Paweł Kuna
Generate SCSS and JS docs snippets from source markers (#2798)
05 авг 2026, 19:44
Не верифицирован
05 авг 2026, 19:44
9c4dc73
Код
Авторство
О чём код?
// js-docs-start countup-init const countupElements: NodeListOf<HTMLElement> = document.querySelectorAll<HTMLElement>('[data-countup]') if (countupElements.length) { countupElements.forEach(function (element: HTMLElement) { let options: Record<string, any> = {} try { const dataOptions = element.getAttribute('data-countup') ? JSON.parse(element.getAttribute('data-countup')!) : {} options = Object.assign( { enableScrollSpy: true, }, dataOptions, ) } catch (error) { // ignore invalid JSON } // Strip thousands separators, currency symbols and other non-numeric characters // so formatted targets like "1,234", "1 234" or "$99.5" parse correctly. const value = parseFloat((element.textContent ?? '').replace(/[^0-9.-]/g, '')) if (!Number.isNaN(value) && window.countUp && window.countUp.CountUp) { const countUp = new window.countUp.CountUp(element, value, options) // When scrollSpy is enabled CountUp starts the animation itself once the // element scrolls into view, so only start manually when it's disabled. if (!countUp.error && !options.enableScrollSpy) { countUp.start() } } }) } // js-docs-end countup-init