i just want to call this code as a function inside an IntersectionObserver:
And i want it to be reusable and cleaner, so i could just it anywhere
//I want this to be a function
numbers.forEach((number, index) => {
intervals[index] = setInterval(() => {
if(counters[index] === parseInt(number.dataset.num)){
clearInterval(counters[index]);
} else{
counters[index] += 1;
number.textContent = counters[index] + "%";
svgEl[index].style.strokeDashoffset = Math.floor(472 - 440 * parseFloat(number.dataset.num / 100));
}
}, 20);
});
}
My IntersectionObserver
const animate = new IntersectionObserver(function (entries, animate) {
entries.forEach(entry => {
if(!entry.isIntersecting) {
//function
}
});
});
animate.observe(test);