-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
235 lines (204 loc) · 7.46 KB
/
Copy pathscript.js
File metadata and controls
235 lines (204 loc) · 7.46 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
document.addEventListener("DOMContentLoaded", function () {
// Mobile Menu Toggle
const menuToggle = document.querySelector(".menu-toggle");
const navUl = document.querySelector("nav ul");
menuToggle.addEventListener("click", function () {
navUl.classList.toggle("active");
});
// Smooth Scrolling for Anchor Links
document.querySelectorAll('a[href^="#"]').forEach((anchor) => {
anchor.addEventListener("click", function (e) {
e.preventDefault();
const targetId = this.getAttribute("href");
if (targetId === "#") return;
const targetElement = document.querySelector(targetId);
if (targetElement) {
// Close mobile menu if open
navUl.classList.remove("active");
window.scrollTo({
top: targetElement.offsetTop - 80,
behavior: "smooth",
});
}
});
});
// Skill Slider
const skillTrack = document.querySelector(".skill-track");
const skillCards = document.querySelectorAll(".skill-card");
const prevBtn = document.querySelector(".prev-btn");
const nextBtn = document.querySelector(".next-btn");
let currentPosition = 0;
const cardWidth = skillCards[0].offsetWidth + 30; // card width + gap
function updateSliderPosition() {
skillTrack.style.transform = `translateX(${
-currentPosition * cardWidth
}px)`;
}
// for the button at the bottom of the page
nextBtn.addEventListener("click", function () {
if (currentPosition < skillCards.length - 3) {
currentPosition++;
updateSliderPosition();
}
});
prevBtn.addEventListener("click", function () {
if (currentPosition > 0) {
currentPosition--;
updateSliderPosition();
}
});
// Auto-advance slider (optional)
let autoSlideInterval = setInterval(() => {
if (currentPosition < skillCards.length - 3) {
currentPosition++;
} else {
currentPosition = 0;
}
updateSliderPosition();
}, 5000);
// Pause auto-slide on hover
const skillsContainer = document.querySelector(".skills-container");
skillsContainer.addEventListener("mouseenter", () => {
clearInterval(autoSlideInterval);
});
skillsContainer.addEventListener("mouseleave", () => {
autoSlideInterval = setInterval(() => {
if (currentPosition < skillCards.length - 3) {
currentPosition++;
} else {
currentPosition = 0;
}
updateSliderPosition();
}, 5000);
});
// Projects Slider
const projectsTrack = document.querySelector(".projects-track");
const projectCards = document.querySelectorAll(".project-card");
const prevProjectBtn = document.querySelector(".prev-project-btn");
const nextProjectBtn = document.querySelector(".next-project-btn");
let currentProjectPosition = 0;
const projectCardWidth = projectCards[0].offsetWidth + 30; // card width + gap
function updateProjectSliderPosition() {
projectsTrack.style.transform = `translateX(${
-currentProjectPosition * projectCardWidth
}px)`;
}
nextProjectBtn.addEventListener("click", function () {
if (currentProjectPosition < projectCards.length - 3) {
currentProjectPosition++;
updateProjectSliderPosition();
}
});
prevProjectBtn.addEventListener("click", function () {
if (currentProjectPosition > 0) {
currentProjectPosition--;
updateProjectSliderPosition();
}
});
// Auto-advance projects slider (optional)
let autoProjectSlideInterval = setInterval(() => {
if (currentProjectPosition < projectCards.length - 3) {
currentProjectPosition++;
} else {
currentProjectPosition = 0;
}
updateProjectSliderPosition();
}, 5000);
// Pause auto-slide on hover for projects
const projectsContainer = document.querySelector(".projects-container");
projectsContainer.addEventListener("mouseenter", () => {
clearInterval(autoProjectSlideInterval);
});
projectsContainer.addEventListener("mouseleave", () => {
autoProjectSlideInterval = setInterval(() => {
if (currentProjectPosition < projectCards.length - 3) {
currentProjectPosition++;
} else {
currentProjectPosition = 0;
}
updateProjectSliderPosition();
}, 5000);
});
// Certificates Modal
const certificateTrigger = document.getElementById("certificate-trigger");
const certificatesModal = document.getElementById("certificates-modal");
const closeModalButtons = document.querySelectorAll(".close-modal");
certificateTrigger.addEventListener("click", function () {
certificatesModal.style.display = "block";
document.body.style.overflow = "hidden";
});
// Contact Modal
const contactBtn = document.getElementById("contact-btn");
const contactModal = document.getElementById("contact-modal");
contactBtn.addEventListener("click", function () {
contactModal.style.display = "block";
document.body.style.overflow = "hidden";
});
// Close Modals
closeModalButtons.forEach((button) => {
button.addEventListener("click", function () {
certificatesModal.style.display = "none";
contactModal.style.display = "none";
document.body.style.overflow = "auto";
});
});
// Close modal when clicking outside
window.addEventListener("click", function (e) {
if (e.target === certificatesModal) {
certificatesModal.style.display = "none";
document.body.style.overflow = "auto";
}
if (e.target === contactModal) {
contactModal.style.display = "none";
document.body.style.overflow = "auto";
}
});
// Form Submission
const contactForm = document.querySelector(".contact-form");
if (contactForm) {
contactForm.addEventListener("submit", function (e) {
e.preventDefault();
// Here you would typically send the form data to a server
alert("Thank you for your message! I will get back to you soon.");
contactModal.style.display = "none";
document.body.style.overflow = "auto";
contactForm.reset();
});
}
// Animate elements when they come into view
const animateOnScroll = function () {
const elements = document.querySelectorAll(
".skill-card, .project-card, .about-content"
);
elements.forEach((element) => {
const elementPosition = element.getBoundingClientRect().top;
const windowHeight = window.innerHeight;
if (elementPosition < windowHeight - 100) {
element.style.opacity = "1";
element.style.transform = "translateY(0)";
}
});
};
// Set initial state for animated elements
document
.querySelectorAll(".skill-card, .project-card, .about-content")
.forEach((element) => {
element.style.opacity = "0";
element.style.transform = "translateY(30px)";
element.style.transition = "opacity 0.5s ease, transform 0.5s ease";
});
window.addEventListener("scroll", animateOnScroll);
animateOnScroll(); // Run once on page load
// New: Animate gradient backgrounds on education cards
const educationCards = document.querySelectorAll(".education-card");
educationCards.forEach((card) => {
card.classList.add("animated-gradient");
});
});
// Track social link clicks
document.querySelectorAll(".social-links a").forEach((link) => {
link.addEventListener("click", function () {
// Send analytics data here
console.log(`Clicked: ${this.href}`);
});
});