-
Hi, I mean. If I scroll my page slowly, and top just when my big 3 counters are barely visible, they all show a static 0. I must scroll a little bit to make the counters start counting. It's not ideal in my case. The animations should be already started just before the counters come into page, otherwise the user will see a potentially too long 'flash' of 3 zerors. I would need something like a 'offset' option that lets you determine an offset for when enableScrollSpy:true. It it possible, or any other way to accomplish this? |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 3 replies
-
Yes, there is an option, |
Beta Was this translation helpful? Give feedback.
-
This is my working solution using just an intersectionObserver: import { CountUp } from "countup.js";
const counters = document.querySelectorAll('.counters-block .counter-number');
var countups = [];
for(const counter of counters){
const tovalue = parseInt(counter.dataset.tovalue, 10);
const countUp = new CountUp(counter.id, tovalue, {
// enableScrollSpy: true,
// scrollSpyDelay: 0,
duration: 3
});
countups.push(countUp);
}
const counters_box = document.querySelector(".counters-box");
let counter_observer = new IntersectionObserver((entries, observer) => {
entries.forEach(entry => {
if(entry.isIntersecting){
for(const countup of countups) countup.start();
} else {
for(const countup of countups) countup.reset();
}
});
});
counter_observer.observe(counters_box); |
Beta Was this translation helpful? Give feedback.
This is my working solution using just an intersectionObserver: