Skip to content

Commit dae2d0e

Browse files
committed
fix: prevent layout shift when starting counting
1 parent e11dc19 commit dae2d0e

File tree

2 files changed

+3
-3
lines changed

2 files changed

+3
-3
lines changed

dist/index.js

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

index.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -27,12 +27,12 @@ const counterUp = ( el, options = {} ) => {
2727
el._countUpOrigInnerHTML = el.innerHTML
2828

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

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

0 commit comments

Comments
 (0)