-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.js
127 lines (114 loc) · 4.05 KB
/
main.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
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
let arrowTop = document.querySelector(".arrow-top");
let awesomeSection = document.querySelector(".ourawesome");
let awesomeContainerNum = document.querySelectorAll(".ourawesome .box .number");
let started = false;
let skillsSection = document.querySelector(".skills");
let skillsContainerSkill = document.querySelectorAll(
".skills .skill .progress span"
);
let pageScroll = document.querySelector(".page-progress");
window.onscroll = function () {
//start arrow top
this.scrollY >= 500
? arrowTop.classList.add("show-top-arrow")
: arrowTop.classList.remove("show-top-arrow");
//End arrow top
//Start Skills Section
if (this.scrollY + 400 > skillsSection.offsetTop) {
skillsContainerSkill.forEach((ele) => {
ele.style.width = ele.dataset.width;
});
}
//End Skills section
//Start awesome Section
if (this.scrollY + 400 > awesomeSection.offsetTop && !started) {
awesomeContainerNum.forEach((ele) => startAwesomeCount(ele));
started = true;
//can search in asyncronase progarmming
// can search in request animation frame
}
//End Awesome section
//start page scroll
pageScroll.style.width = `${
(document.documentElement.scrollTop /
(document.documentElement.scrollHeight -
document.documentElement.clientHeight)) *
100
}%`;
//Edn page scroll
};
//start arrow top
arrowTop.onclick = function () {
window.scrollTo({
top: 0,
behavior: "smooth",
});
};
//End arrow top
//Start Awesome Count
function startAwesomeCount(ele) {
let dataGoal = ele.dataset.goal;
let count = setInterval(() => {
ele.textContent++;
if (ele.textContent == dataGoal) {
clearInterval(count);
}
}, 3000 / dataGoal);
}
//End Awesome Count
//Start event time change
let eventSecs = document.querySelector(".events .time .seconds");
let eventMins = document.querySelector(".events .time .minutes");
let eventHours = document.querySelector(".events .time .hours");
let eventDays = document.querySelector(".events .time .days");
let EventWantTimer = new Date("Aug 15, 2024 23:59:59");
let days, hours, minutes, seconds;
// Get Date Now
let dateNow = new Date().getTime();
//find the date difference between now and event time
let dateDiff = EventWantTimer - dateNow;
let startEventTimer = setInterval(() => {
dateDiff -= 1000;
// Get time units
days = Math.floor(dateDiff / (1000 * 60 * 60 * 24));
hours = Math.floor((dateDiff % (1000 * 60 * 60 * 24)) / (1000 * 60 * 60));
minutes = Math.floor((dateDiff % (1000 * 60 * 60)) / (1000 * 60));
seconds = Math.floor((dateDiff % (1000 * 60)) / 1000);
eventSecs.innerHTML = seconds < 10 ? `0${seconds}` : seconds;
eventMins.innerHTML = minutes < 10 ? `0${minutes}` : minutes;
eventHours.innerHTML = hours < 10 ? `0${hours}` : hours;
eventDays.innerHTML = days < 10 ? `0${days}` : days;
if (dateDiff < 1000) clearInterval(startEventTimer);
}, 1000);
//End event time change
//Start Top Videos
let topVideosLinks = document.querySelectorAll(".topvideos ul li");
topVideosLinks.forEach((ele) => {
ele.addEventListener("click", function (e) {
changeTopVideos(e.currentTarget);
});
});
let btnShuffleTopVideos = document.querySelector(".topvideos .shuffle-icon");
btnShuffleTopVideos.onclick = function () {
let rndmIndx = Math.floor(Math.random() * topVideosLinks.length);
changeTopVideos(topVideosLinks[rndmIndx]);
};
function changeTopVideos(e) {
//remove active class from all
topVideosLinks.forEach((ele) => {
ele.classList.remove("active");
});
//add active class to clicked one
e.classList.add("active");
//add img to preview
document
.querySelector(".topvideos .preview img")
.setAttribute("src", `images/${e.dataset.preview}.jpg`);
//change video headline
document.querySelector(".topvideos .preview .info > div").textContent =
e.firstChild.textContent;
//change video Time
document.querySelector(".topvideos .preview .info > span").textContent =
e.lastChild.textContent;
}
//End Top Video