-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.js
More file actions
56 lines (47 loc) · 1.23 KB
/
main.js
File metadata and controls
56 lines (47 loc) · 1.23 KB
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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
let toBtn = document.querySelector(".scroll-top");
window.addEventListener("scroll", function () {
if (this.scrollY >= 574) {
toBtn.classList.add("show");
} else {
toBtn.classList.remove("show");
}
});
toBtn.onclick = function () {
window.scrollTo({
top: 0,
behavior: "smooth",
});
};
// get nums pulsing
let nums = document.querySelectorAll(".stats .container .stat-box .number");
let section = document.querySelector(".stats");
let started = false;
window.addEventListener("scroll", function () {
if (window.scrollY >= section.offsetTop - 100) {
if (!started) {
nums.forEach((num) => startCount(num));
}
started = true;
}
});
function startCount(el) {
let goal = el.dataset.goal;
let count = setInterval(() => {
el.textContent++;
if (el.textContent == goal) {
clearInterval(count);
}
}, 2000 / goal);
}
// get progress pulsing
let progressSpans = document.querySelectorAll(
".our-skills .skills .prog-holder span"
);
let progSection = document.querySelector(".our-skills");
window.addEventListener("scroll", function () {
if (window.scrollY >= progSection.offsetTop + 50) {
progressSpans.forEach((span) => {
span.style.width = span.dataset.width;
});
}
});