Good day!
I'm trying to use simple setInterval() with onEnter() of ScrollTrigger.
The code works. The ScrollTrigger - triggers. But together they don't work.
Hers is the code:
Value animate function:
const animateValue = (startVal, finishVal, durationVal) => {
//
let startValue = startVal;
let finishValue = finishVal;
let duration = durationVal;
let increment = Math.trunc(((finishValue - startValue) / duration) * 50);
let current = startValue;
let interval = setInterval(() => {
//
current += increment;
if (current >= finishValue) {
clearInterval(interval);
current = finishValue;
}
console.log(current);
//
}, 10);
};
ScrollTrigger
const odometersAll = gsap.utils.toArray('[data-odometer]');
//
//
odometersAll.forEach((odometer) => {
//
ScrollTrigger.create({
trigger: odometer,
start: '-240px 30%',
markers: true,
onEnter: () => {
//
animateValue(
parseInt(odometer.dataset.odometer),
parseInt(odometer.textContent),
3000
);
//
},
});
//
});
What is the issue?
Thanks in advance!