-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
225 lines (170 loc) · 5.71 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
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
const heroSection = document.querySelector(".section-hero");
// ========================================
// creating a responsive navbar component
// ========================================
const mobile_nav = document.querySelector(".mobile-navbar-btn");
const headerElem = document.querySelector(".header");
mobile_nav.addEventListener('click', () => {
headerElem.classList.toggle("active");
});
// ========================================
// creating a sticky navbar
// ========================================
const observer = new IntersectionObserver((entries) => {
const ent = entries[0];
!ent.isIntersecting ? document.body.classList.add("sticky") : document.body.classList.remove("sticky");
}, {
root: null,
threshold: 0,
});
if (heroSection != null) {
observer.observe(heroSection);
}
// ========================================
// creating a portfolio tabbed component
// ========================================
const p_btns = document.querySelector(".p-btns");
const p_btn = document.querySelectorAll(".p-btn");
const p_img_elem = document.querySelectorAll(".img-overlay");
if (p_btns != null) {
p_btns.addEventListener('click', (e) => {
const p_btn_clicked = e.target;
if (!p_btn_clicked.classList.contains('p-btn')) return;
// in-active when clicked again
if (p_btn_clicked.classList.contains('p-btn-active')) {
p_btn_clicked.classList.remove("p-btn-active");
p_img_elem.forEach((curnElem) => curnElem.classList.remove('p-image-not-active'));
return;
}
p_btn.forEach((curnElem) => curnElem.classList.remove("p-btn-active"));
p_btn_clicked.classList.add("p-btn-active");
// to find the number in data attr
const btn_num = p_btn_clicked.dataset.btnNum;
// console.log(btn_num);
const img_active = document.querySelectorAll(`.p-btn--${btn_num}`);
p_img_elem.forEach((curnElem) => curnElem.classList.add('p-image-not-active'));
img_active.forEach((curnElem) => curnElem.classList.remove('p-image-not-active'));
// p_img_elem
// p-btn--1
});
}
// swiper js code
var swiper = new Swiper(".mySwiper", {
slidesPerView: 2,
spaceBetween: 30,
autoplay: {
delay: 2500
},
pagination: {
el: ".swiper-pagination",
clickable: true,
},
});
const myJsmedia = (widthSize) => {
if (widthSize.matches) {
new Swiper(".mySwiper", {
slidesPerView: 1,
spaceBetween: 30,
});
} else {
new Swiper(".mySwiper", {
slidesPerView: 2,
spaceBetween: 30,
});
}
}
const widthSize = window.matchMedia('(max-width:780px)');
// Call listener function at run time
myJsmedia(widthSize);
// Attach listener function on state changes
widthSize.addEventListener('change', myJsmedia)
// ========================================
// scroll to top
// ========================================
const footerElem = document.querySelector(".section-footer");
if (heroSection != null) {
const scrollElement = document.createElement("div");
scrollElement.classList.add("scrollTop-style");
scrollElement.innerHTML = `<ion-icon name="arrow-up-outline" class="scroll-top"></ion-icon>`;
footerElem.after(scrollElement);
const scrollToTop = () => {
// heroSection.scrollIntoView({ behavior: "smooth" });
const topDistance = document.documentElement.scrollTop || document.body.scrollTop;
if (topDistance > 0) {
window.requestAnimationFrame(scrollToTop);
window.scrollTo(0, topDistance - topDistance / 8);
}
};
scrollElement.addEventListener("click", scrollToTop);
}
// ========================================
// animated counter number
// ========================================
const workSection = document.querySelector(".section-work-data");
const workObserver = new IntersectionObserver((entries, observer) => {
const [entry] = entries;
// console.log(entry);
// if(!entry.isIntersecting == false);
if (!entry.isIntersecting) return;
// animate number counter
const counterNum = document.querySelectorAll(".counter-numbers");
const speed = 200;
counterNum.forEach((curnElem) => {
const updateNumber = () => {
const targetNumber = parseInt(curnElem.dataset.number);
// console.log((targetNumber));
const initialNum = parseInt(curnElem.innerText);
// console.log(initialNum);
const increamentNumber = Math.trunc(targetNumber / speed);
// console.log(increamentNumber);
if (initialNum < targetNumber) {
curnElem.innerText = `${initialNum + increamentNumber}+`;
setTimeout(updateNumber, 10);
}
};
updateNumber();
});
observer.unobserve(workSection);
}, {
root: null,
threshold: 0,
});
if (workSection != null) {
workObserver.observe(workSection);
}
// ========================================
// lazy loading section
// ========================================
const imgRef = document.querySelector("img[data-src]");
// console.log(imgRef);
const lazyImg = (entries) => {
const [entry] = entries;
if (!entry.isIntersecting) return;
entry.target.src = imgRef.dataset.src;
};
const imgObserver = new IntersectionObserver(lazyImg, {
root: null,
threshold: 0,
// rootMargin: "100px",
});
if (imgRef != null) {
imgObserver.observe(imgRef);
}
/* Below is a code for blocking inspect, right click in homepage date: 07-09-2022 */
if (heroSection != null && false) {
document.addEventListener('contextmenu', event => event.preventDefault());
document.onkeydown = function (e) {
if (event.keyCode == 123) {
return false;
}
if (e.ctrlKey && e.shiftKey && e.keyCode == 'I'.charCodeAt(0)) {
return false;
}
if (e.ctrlKey && e.shiftKey && e.keyCode == 'J'.charCodeAt(0)) {
return false;
}
if (e.ctrlKey && e.keyCode == 'U'.charCodeAt(0)) {
return false;
}
}
}