-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
79 lines (65 loc) · 2.57 KB
/
index.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
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
////////////////////////////////////// Countdown Timer /////////////////////////////////////////////////////////
// The End Of The Year Date
// 1000 milliseconds = 1 Second
let countDownDate = new Date("Dec 31, 2022 23:59:59").getTime();
// console.log(countDownDate);
let counter = setInterval(() => {
// Get Date Now
let dateNow = new Date().getTime();
// Find The Date Difference Between Now And Countdown Date
let dateDiff = countDownDate - dateNow;
// Get Time Units
// let days = Math.floor(dateDiff / 1000 / 60 / 60 / 24);
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);
////////////////////////////////////// End Countdown Timer /////////////////////////////////////////////////////////
///////////////////////////////////// Animate Width On Scrolling ///////////////////////////////////////////////////
/*
** Increase Numbers On Scrolling
*/
let progressSpans = document.querySelectorAll(".progress span");
let section = document.querySelector(".our-skills");
let nums = document.querySelectorAll(".stats .number");
let statsSection = document.querySelector(".stats");
let started = false; // Function Started ? No
window.onscroll = function () {
// Skills Animate Width
if (window.scrollY >= section.offsetTop - 250) {
progressSpans.forEach((span) => {
span.style.width = span.dataset.width;
});
}
// Stats Increase Number
if (window.scrollY >= statsSection.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);
}
//////////////// Copyright /////////////////////////
const currentYear = new Date().getFullYear();
let copyrightSpan = document.querySelector(".c-date");
let paragraph = `Copyright © ${currentYear} All Rights Reserved`;
copyrightSpan.innerHTML = paragraph;