-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.js
35 lines (30 loc) · 928 Bytes
/
app.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
const section_counter = document.querySelector("#section__counter");
const counters = document.querySelectorAll(".numbers");
function runCounter(){
counters.forEach(counter => {
counter.innerText = 0;
let target = +counter.dataset.target;
let step = target / 100;
let countIt = function(){
let displayedCount = +counter.innerText;
if(displayedCount < target){
counter.innerText = Math.ceil(displayedCount + step);
setTimeout(countIt, 10);
} else{
counter.innerText = target;
}
}
countIt();
});
}
runCounter();
let options = {
rootMargin: '0px 0px 0px 0px',
threshold: 1.0
}
let sectionObserver = new IntersectionObserver(function(entries){
if(entries[0].isIntersecting){
runCounter();
}
}, options);
sectionObserver.observe(section_counter);