forked from Mar1a0l1ve1ra/CPX
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
142 lines (126 loc) · 4.19 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
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
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
$(document).ready(function () {
// Animation for numbers start
gsap.registerPlugin(ScrollTrigger);
let stats = $(".statsBannerCard__statistic").toArray();
function countOne(stat) {
$(stat).css({
visibility: "visible",
});
let count = $(stat),
zero = {
val: 0,
},
num = count.data("number"),
split = (num + "").split("."), // to cover for instances of decimals
decimals = split.length > 1 ? split[1].length : 0;
if (typeof num == "number") {
gsap.to(zero, {
val: num,
duration: 2,
scrollTrigger: {
trigger: stat,
start: "top 92%",
onEnter: function () {
gsap.to(zero, {
val: num,
duration: 2,
onUpdate: function () {
let numText = zero.val.toFixed(decimals);
numText = numText.replace(/(\d)(?=(\d{3})+(?!\d))/g, "$1,");
count.text(numText);
},
});
},
},
});
} else {
count.text(num);
}
}
// Iterate through all stats and initiate the count animation
stats.forEach((stat) => {
countOne(stat);
});
// Animation for numbers end
// Handle sidebar start
let bodyy = document.getElementById("body");
let cancel = document.getElementById("cancel");
let btn = document.getElementById("navbtn");
let sidebar = document.getElementById("sidebarbtn");
let navLinks = document.querySelectorAll(".nav-link");
let sidebarOverlay = document.getElementById("sidebar-overlay");
const handleSidebar = () => {
sidebar.style.left = "-105%";
bodyy.style.overflow = "auto";
sidebarOverlay.style.display = "none";
};
btn.addEventListener("click", () => {
sidebar.style.left = "0";
bodyy.style.overflow = "hidden";
sidebarOverlay.style.display = "block";
});
cancel.addEventListener("click", handleSidebar);
sidebarOverlay.addEventListener("click", handleSidebar);
navLinks.forEach(function (navLink) {
navLink.addEventListener("click", handleSidebar);
});
// Handle sidebar end
// Language dropdown start
document.addEventListener("click", (event) => {
const dropdownMenu = document.getElementById("languageDropdown");
const isDropdownButton = event.target.closest("#languageDropdownButton");
if (isDropdownButton) {
dropdownMenu.classList.toggle("hidden");
} else if (!event.target.closest("#languageDropdown")) {
dropdownMenu.classList.add("hidden");
}
const link = event.target.closest("#languageDropdown a");
if (link) {
event.preventDefault();
document.getElementById("languageText").textContent =
link.getAttribute("data-value");
dropdownMenu.classList.add("hidden");
window.location.href = link.href;
}
});
// Sidebar language dropdown start
document.addEventListener("click", (event) => {
const sidebarDropdownMenu = document.getElementById(
"sidebarLanguageDropdown"
);
const isSidebarDropdownButton = event.target.closest(
"#sidebarLanguageDropdownButton"
);
if (isSidebarDropdownButton) {
sidebarDropdownMenu.classList.toggle("hidden");
} else if (!event.target.closest("#sidebarLanguageDropdown")) {
sidebarDropdownMenu.classList.add("hidden");
}
const sidebarLink = event.target.closest("#sidebarLanguageDropdown a");
if (sidebarLink) {
event.preventDefault();
document.getElementById("sidebarLanguageText").textContent =
sidebarLink.getAttribute("data-value");
sidebarDropdownMenu.classList.add("hidden");
window.location.href = sidebarLink.href;
}
});
// To scroll window to top
let scrollToTopBtn = document.getElementById("scrollToTop");
scrollToTopBtn.addEventListener("click", () => {
const heroSection = document.getElementById("hero");
heroSection.scrollIntoView({
behavior: "smooth",
block: "start",
inline: "nearest",
});
});
// To show scroll window to top button after user scroll down
window.addEventListener("scroll", () => {
if (window.scrollY > 200) {
scrollToTopBtn.classList.remove("hidden");
} else {
scrollToTopBtn.classList.add("hidden");
}
});
});