Sorry I have used incorrect attribute.
import { gsap, ScrollTrigger } from 'gsap/all.js';
gsap.registerPlugin( ScrollTrigger );
export default class Counter {
constructor() {
this.timeline();
}
timeline() {
const counters = document.querySelectorAll( 'span.counter' );
counters.forEach( ( counter ) => {
if (
counter.parentElement.getAttribute( 'data-counter-duration' )
) {
const scroll = counter.parentElement.getAttribute(
'data-counter-scroll'
);
const comma = counter.parentElement.getAttribute(
'data-counter-comma'
);
const tl = gsap.timeline( {
paused: true,
scrollTrigger: {
trigger: counter,
toggleActions:
scroll === 'true'
? 'restart none none none'
: 'play none none none',
},
} );
tl.from( counter, {
textContent: 0,
duration: counter.parentElement.getAttribute(
'data-counter-duration'
),
ease: 'power1.in',
snap: { textContent: 1 },
} );
}
} );
}
numberWithCommas( number ) {
return number.toString().replace(/\B(?=(\d{3})+(?!\d))/g, ",");
}
}
How can I apply numberWithCommas so it will work like in the following example ?https://codepen.io/akapowl/pen/bGwJaqo/b2c2c56064274fd14620faa9d5537e40