-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathscript.js
More file actions
158 lines (127 loc) · 4.29 KB
/
script.js
File metadata and controls
158 lines (127 loc) · 4.29 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
// Back-To-Top Button Section
let mybutton = document.getElementById("Back-To-Top");
window.onscroll = function () {
scrollFunction();
};
function scrollFunction() {
if (
document.body.scrollTop > 20 ||
document.documentElement.scrollTop > 20
) {
mybutton.style.display = "block";
} else {
mybutton.style.display = "none";
}
}
mybutton.addEventListener("click", backToTop);
function backToTop() {
window.scrollTo({
top: 0,
behavior: "smooth"
});
}
// Hamburger Menu Section
const hamburger = document.getElementById('hamburger');
const overlay = document.getElementById('overlay');
const overlayLinks = document.querySelectorAll('.overlay-links a');
const icon = hamburger.querySelector('i');
hamburger.addEventListener('click', () => {
const isOpen = hamburger.classList.toggle('open');
overlay.style.display = isOpen ? 'flex' : 'none';
document.body.style.overflow = isOpen ? 'hidden' : '';
icon.className = isOpen
? 'fa-solid fa-bars-staggered'
: 'fa-solid fa-bars';
});
overlayLinks.forEach(link => {
link.addEventListener('click', () => {
overlay.style.display = 'none';
hamburger.classList.remove('open');
icon.className = 'fa-solid fa-bars';
document.body.style.overflow = '';
});
});
// Read More Button Section
document.addEventListener("DOMContentLoaded", function () {
const readMoreBtn = document.querySelector('.read-more-btn');
const moreText = document.querySelector('.more-text');
const icon = document.querySelector('.arrow-icon');
readMoreBtn.addEventListener('click', function () {
moreText.classList.toggle('active');
icon.classList.toggle('rotate');
});
});
// Project Expand Section
document.addEventListener("DOMContentLoaded", function () {
const projects = document.querySelectorAll(".projects-card");
projects.forEach(project => {
project.addEventListener("click", function () {
this.classList.toggle("expanded");
});
});
});
// Form Feedback Section
document.getElementById('fs-frm').addEventListener('submit', async function (event) {
event.preventDefault();
const form = event.target;
const status = document.getElementById('form-status');
const data = new FormData(form);
try {
const response = await fetch("https://formspree.io/f/mknlbraw", {
method: "POST",
headers: { 'Accept': 'application/json' },
body: data
});
if (response.ok) {
status.innerHTML = "<span style='color:green; font-size:large; font-weight:450; letter-spacing:-1px;'>Thanks! Your message has been sent.</span>";
form.reset();
} else {
const result = await response.json();
status.innerHTML = "<span style='color:red; font-size:large; font-weight:450; letter-spacing:-1px;'>Oops! " + (result.error || "There was a problem submitting your form.") + "</span>";
}
} catch (error) {
status.innerHTML = "<span style='color:red; font-size:large; font-weight:450; letter-spacing:-1px;'>Oops! There was a network error. Please try again.</span>";
}
});
// Dynamic Space Section
const formStatus = document.getElementById('form-status');
const contactCard = document.querySelector('.contact-card');
const observer = new MutationObserver(() => {
if (formStatus.textContent.trim()) {
contactCard.classList.add('no-bottom-padding');
} else {
contactCard.classList.remove('no-bottom-padding');
}
});
observer.observe(formStatus, { childList: true, subtree: true });
// Block Pinch-to-Zoom on the Website
document.addEventListener('wheel', function (e) {
if (e.ctrlKey) {
e.preventDefault();
}
}, { passive: false });
// Page Loader Section
document.addEventListener("DOMContentLoaded", function () {
const loader = document.getElementById("page-loader");
const loadingNumber = document.getElementById("loading-number");
const duration = 1500;
const startTime = performance.now();
function animate(time) {
const elapsed = time - startTime;
const progress = Math.min(elapsed / duration, 1);
const value = Math.floor(progress * 100);
loadingNumber.textContent = value + "%";
if (progress < 1) {
requestAnimationFrame(animate);
} else {
fadeOut();
}
}
function fadeOut() {
loader.classList.add("hide");
setTimeout(() => {
loader.remove();
}, 1000);
}
requestAnimationFrame(animate);
});