I have multiple number counters on a page and I want them to start when they get into view, not when you get to the page as they are in the middle of the page. The code that I am using is below, this code works but only when you first visit the page. I have seen some suggestions on here but nothing has worked for me.
let startNum = 0 ;
let endNum = 34 ;
const duration = 150 ;
$w . onReady ( function () { setInterval (() => { countUp (); }, duration ); });
function countUp ( ) {
if ( startNum <= endNum ) {
$w ( ‘#textnumber1’ ). text = startNum . toString ();
startNum ++;
}
}
let startNum1 = 0 ;
let endNum1 = 27 ;
const duration1 = 150 ;
$w . onReady ( function () { setInterval (() => { countUp1 (); }, duration1 ); });
function countUp1 ( ) {
if ( startNum1 <= endNum1 ) {
$w ( ‘#textnumber2’ ). text = startNum1 . toString ();
startNum1 ++;
}
}