/
githubmirror
/
50projects50days
Обзор
Документация
Войти
/
githubmirror
/
50projects50days
Код
Запросы
0
Пакеты
0
Релизы
0
Аналитика
Безопасность
master
incrementing-counter/script.js
21 строка
510 B
Brad Traversy
Incrementing counter
16 окт 2020, 20:24
16 окт 2020, 20:24
adcd5f2
Код
Авторство
О чём код?
const counters = document.querySelectorAll('.counter') counters.forEach(counter => { counter.innerText = '0' const updateCounter = () => { const target = +counter.getAttribute('data-target') const c = +counter.innerText const increment = target / 200 if(c < target) { counter.innerText = `${Math.ceil(c + increment)}` setTimeout(updateCounter, 1) } else { counter.innerText = target } } updateCounter() })