-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
255 lines (202 loc) · 8.49 KB
/
Copy pathscript.js
File metadata and controls
255 lines (202 loc) · 8.49 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
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
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
/* ++++++++++ Header and Home ++++++++++ */
const BoundingAnime = () => {
var tl = gsap.timeline()
tl.from("header", {
y: "-10",
opacity: 0,
duration: 1,
ease: Expo.easeInOut
})
.to(".bounding-elem", {
opacity: 1,
y: 0,
duration: 2,
stagger: .2,
delay: -1,
ease: Expo.easeInOut
})
}
BoundingAnime()
/* ++++++++++ Nav ++++++++++ */
function monitorNavToAssignActiveClass(className, navSelector, offset = 250) {
const sections = document.querySelectorAll('section');
const navLinks = document.querySelectorAll(`${navSelector} a`);
function onScroll() {
const scrollPos = window.scrollY + offset;
sections.forEach((section, index) => {
if (scrollPos >= section.offsetTop && scrollPos < section.offsetTop + section.offsetHeight) {
navLinks.forEach(link => link.closest("li").classList.remove(className));
navLinks[index].closest("li").classList.add(className);
}
});
}
window.addEventListener('scroll', onScroll);
onScroll(); // Initialize on page load
}
monitorNavToAssignActiveClass("active-nav-link", 'header nav ul');
/* ++++++++++ Skill Section ++++++++++ */
function infiniteScroll(){
const _infiniteScrollParent = document.querySelectorAll(".infinite-scroll");
for (let infiniteScrollParent of _infiniteScrollParent){
const computedStyle = getComputedStyle(infiniteScrollParent.querySelector(".infinite-scroll > .scroll-item"));
const duration = Number.parseInt(computedStyle.animationDuration);
const totalItems = infiniteScrollParent.querySelectorAll(`.scroll-item`).length;
const itemsArr = Array.from(infiniteScrollParent.querySelectorAll(".scroll-item"))
itemsArr.forEach((elem, index) => {
let formula = (duration / totalItems * (totalItems - index) * -1);
elem.style.animationDelay = `${formula}s`
elem.style.animationDuration = `${duration}s`
});
}
}
infiniteScroll()
/* ++++++++++ Project Section ++++++++++ */
const MouseFollowerFor3dImageEffect = (effectIntensity=10) => {
let imageRotateTime;
this.clearTimeout(imageRotateTime);
imageRotateTime = setTimeout(() => {
document.querySelectorAll(".project .thumbnail").forEach(function(elem) {
elem.addEventListener("mousemove", function(dets) {
// Get the bounding box of the element and calculate the cursor's relative position
let itemInfo = elem.getBoundingClientRect();
let diffX = dets.clientX - itemInfo.left; // X-axis distance from left
let diffY = dets.clientY - itemInfo.top; // Y-axis distance from top
// Calculate the center of the element
let centerX = itemInfo.width / 2;
let centerY = itemInfo.height / 2;
// Calculate rotation values based on distance from center
let rotateY = ((diffX - centerX) / centerX) * effectIntensity; // Rotate Y based on X distance
let rotateX = -((diffY - centerY) / centerY) * effectIntensity; // Rotate X based on Y distance
// Apply the transformation to the image
let item = elem.querySelector("img");
item.style.transform = `rotateX(${rotateX}deg) rotateY(${rotateY}deg) translateZ(30px)`;
});
// Reset rotation on mouse leave
elem.addEventListener("mouseleave", function() {
let item = elem.querySelector("img");
item.style.transform = "";
});
});
}, 100);
}
MouseFollowerFor3dImageEffect(10)
/* ++++++++++ Home Section ++++++++++ */
const TypeWriter = (textElementId, texts_arr, typingSpeed=100, pauseBetweenTexts=2000) => {
// typingSpeed -> Time between each character (in ms)
// pauseBetweenTexts -> Pause between each full text (in ms)
let currentTextIndex = 0;
let charIndex = 0;
const textElement = document.getElementById(textElementId);
function typeWriterEffect() {
// Check if all characters of the current text are typed
if (charIndex < texts_arr[currentTextIndex].length) {
textElement.textContent += texts_arr[currentTextIndex][charIndex];
charIndex++;
setTimeout(typeWriterEffect, typingSpeed);
} else {
// Pause after finishing a text, then erase it and move to the next
setTimeout(() => {
eraseText();
}, pauseBetweenTexts);
}
}
function eraseText() {
if (charIndex > 0) {
textElement.textContent = textElement.textContent.slice(0, charIndex - 1);
charIndex--;
setTimeout(eraseText, typingSpeed / 2);
} else {
// Move to the next text in the array
currentTextIndex = (currentTextIndex + 1) % texts_arr.length;
typeWriterEffect();
}
}
typeWriterEffect();
}
const texts_arr = ["Web Developer", "Development"];
TypeWriter("text", texts_arr);
/* ++++++++++ Contact Section ++++++++++ */
const pictureHoverMover = () => {
document.querySelectorAll(".elem").forEach(function (elem) {
var rotate = 0;
var diffrot = 0;
elem.addEventListener("mouseleave", function (dets) {
gsap.to(elem.querySelector("svg"), {
opacity: 0,
ease: Power3,
duration: 0.5,
});
});
elem.addEventListener("mousemove", function (dets) {
var diff = dets.clientY - elem.getBoundingClientRect().top;
diffrot = dets.clientX - rotate;
rotate = dets.clientX;
gsap.to(elem.querySelector("svg"), {
opacity: 1,
ease: Power3,
top: diff,
left: dets.clientX,
rotate: gsap.utils.clamp(-20, 20, diffrot * 0.5)
});
});
});
}
pictureHoverMover()
/* ++++++++++ Auto Experience total time/date calculator ++++++++++ */
const timeSeperatorElement = "∙";
const calculateTotalTime = (startTimeElemTextContent, endTimeElemTextContent) => {
const startTime = new Date(startTimeElemTextContent);
const endTime = (endTimeElemTextContent
.trim().toLowerCase() === "present"
? new Date() :
new Date(endTimeElemTextContent));
const totalYears = endTime.getFullYear() - startTime.getFullYear();
const totalMonths = totalYears * 12 + (endTime.getMonth() - startTime.getMonth());
const years = Math.floor(totalMonths / 12);
const months = totalMonths % 12;
let totalTimeText = "";
if (years > 0) {
totalTimeText += `${years} yr${years > 1 ? 's' : ''} `;
}
if (months > 0) {
totalTimeText += `${months} mo${months > 1 ? 's' : ''}`;
}
// If less than a month, assume 1 month
else{
totalTimeText = "1 mo";
}
return totalTimeText.trim();
}
const allJobs = document.querySelectorAll(".exp-card");
allJobs.forEach((job) => {
try{
/* Calculate the total job time */
const totalJobTime = job.querySelector(".exp-total-time");
const startTimeElemTextContent = job.querySelector(".start-time");
const endTimeElemTextContent = job.querySelector(".end-time");
if (!startTimeElemTextContent || !endTimeElemTextContent){
console.log("SUK card just hit!");
// console.log("Start/End Time element not found");
return;
}
const totalTimeText = calculateTotalTime(startTimeElemTextContent.textContent, endTimeElemTextContent.textContent);
totalJobTime.textContent = ` ${timeSeperatorElement} ${totalTimeText.trim()}`;
// Calculate the total time for each job level
const jobLevels = job.querySelectorAll(".exp-job-level");
jobLevels.forEach((jobLevel)=>{
const timeStampElem = jobLevel.querySelector(".exp-job-timestamp");
if (!timeStampElem){
console.log("TimeStamp element not found");
return;
}
const startTimeElemTextContent = timeStampElem.textContent.split(" - ")[0];
const endTimeElemTextContent = timeStampElem.textContent.split(" - ")[1];
const totalTimeText = calculateTotalTime(startTimeElemTextContent, endTimeElemTextContent);
timeStampElem.textContent += ` ${timeSeperatorElement} ${totalTimeText.trim()}`;
});
}
catch(err){
console.log("SUK = Saadullah Khan!");
}
});
/* XXXXXXXXXX END OF SCRIPT XXXXXXXXXX */