function animate(obj, initVal, lastVal, duration, suffix){
let startTime=null;
let currentTime=Date.now();
const step=(currentTime)=> {
if(!startTime){
startTime=currentTime ;
}
const progress=Math.min((currentTime - startTime)/ duration, 1);
obj.innerHTML.slice(0, -1);
obj.innerHTML=Math.floor(progress * (lastVal - initVal) + initVal) + suffix;
if(progress < 1){
window.requestAnimationFrame(step);
}else{
window.cancelAnimationFrame(window.requestAnimationFrame(step));
}};
window.requestAnimationFrame(step);
}
let text1=document.getElementById('an-1');
let text2=document.getElementById('an-2');
let text3=document.getElementById('an-3');
let text4=document.getElementById('an-4');
let targetElement=document.getElementById("an-2");
let parentElement=targetElement.parentNode;
let grandParentElement=parentElement.parentNode;
let row2037596795=grandParentElement.parentNode;
let ani=0;
function isInViewport(element){
let rect=row2037596795.getBoundingClientRect();
return (
rect.top >=0 &&
rect.left >=0 &&
rect.bottom <=(window.innerHeight||document.documentElement.clientHeight) &&
rect.right <=(window.innerWidth||document.documentElement.clientWidth)
);
}
if(isInViewport(row2037596795)){
if(ani===0){
ani=1;
animate(text1, 0, 100, 2500, "%");
animate(text2, 0, 6000, 3000, "+");
animate(text3, 0, 20, 1500, "+");
animate(text4, 0, 2017, 3500, "");
}}
window.addEventListener("scroll", function(){
if(isInViewport(row2037596795)){
if(ani===1) return;
ani=1;
animate(text1, 0, 100, 2500, "%");
animate(text2, 0, 6000, 3000, "+");
animate(text3, 0, 20, 1500, "+");
animate(text4, 0, 2017, 3500, "");
}});