Skip to content

Commit

Permalink
fix: prevent layout shift when starting counting
Browse files Browse the repository at this point in the history
  • Loading branch information
bfintal committed Aug 4, 2021
1 parent e11dc19 commit dae2d0e
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 3 deletions.
2 changes: 1 addition & 1 deletion dist/index.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,12 @@ const counterUp = ( el, options = {} ) => {
el._countUpOrigInnerHTML = el.innerHTML

// Start counting.
el.innerHTML = nums[ 0 ]
el.innerHTML = nums[ 0 ] || ' ' // Use a non-breaking space to prevent layout shift.
el.style.visibility = 'visible'

// Function for displaying output with the set time and delay.
const output = function() {
el.innerHTML = nums.shift()
el.innerHTML = nums.shift() || ' ' // Use a non-breaking space to prevent layout shift.
if ( nums.length ) {
clearTimeout( el.countUpTimeout )
el.countUpTimeout = setTimeout( output, delay )
Expand Down

0 comments on commit dae2d0e

Please sign in to comment.