-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.js
More file actions
80 lines (67 loc) · 2.2 KB
/
main.js
File metadata and controls
80 lines (67 loc) · 2.2 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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
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 .stats-container .stat p");
let section = document.querySelector(".stats");
let started = false;
window.addEventListener("scroll", function () {
if (window.scrollY >= section.offsetTop) {
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 .container .skills-container .skill .progress 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;
});
}
});
// count down timer
let countDownDat = new Date("Jan 16, 2024 00:00:01").getTime();
let counter = setInterval(() => {
// get date now
let dateNow = new Date().getTime();
// find a deference between time time now an from start time
let dateDiff = countDownDat - dateNow;
// get time unit
let days = Math.floor(dateDiff / (1000 * 60 * 60 * 24));
let hours = Math.floor((dateDiff % (1000 * 60 * 60 * 24)) / (1000 * 60 * 60));
let minutes = Math.floor((dateDiff % (1000 * 60 * 60)) / (1000 * 60));
let seconds = Math.floor((dateDiff % (1000 * 60)) / 1000);
document.querySelector(".days").innerHTML = days < 10 ? `0${days}` : days;
document.querySelector(".hours").innerHTML = hours < 10 ? `0${hours}` : hours;
document.querySelector(".minutes").innerHTML = minutes < 10 ? `0${minutes}` : minutes;
document.querySelector(".seconds").innerHTML = seconds < 10 ? `0${seconds}` : seconds;
if (dateDiff < 0) {
clearInterval(counter);
}
}, 1000);