Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <script>
- let start // set on the first step to the timestamp provided
- const el = document.getElementById('count') // get the element
- const final = parseInt(el.textContent, 10) // parse out the final number
- const duration = 4000 // duration in ms
- const step = ts => {
- if (!start) {
- start = ts
- }
- // get the time passed as a fraction of total duration
- let progress = (ts - start) / duration
- el.textContent = Math.floor(progress * final) // set the text
- if (progress < 1) {
- /*if we are not 100% complete, request another animation frame*/
- requestAnimationFrame(step)
- }
- }
- /*start the animation*/
- requestAnimationFrame(step);
- </script>
- <span id="count">200</span>%
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement