-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
177 lines (148 loc) · 5.14 KB
/
script.js
File metadata and controls
177 lines (148 loc) · 5.14 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
// Smooth Scrolling for same-page anchors
document.querySelectorAll('a[href^="#"]').forEach(anchor => {
anchor.addEventListener('click', function (e) {
const href = this.getAttribute('href');
if (href.startsWith('#') && document.querySelector(href)) {
e.preventDefault();
const target = document.querySelector(href);
if (target) {
target.scrollIntoView({
behavior: 'smooth',
block: 'start'
});
}
}
// Close mobile menu
document.getElementById('navLinks').classList.remove('active');
});
});
// Mobile Menu Toggle
const menuToggle = document.getElementById('menuToggle');
const navLinks = document.getElementById('navLinks');
const links = document.querySelectorAll('#navLinks a'); // all nav links
menuToggle.addEventListener('click', () => {
menuToggle.classList.toggle('active'); // animate to X
navLinks.classList.toggle('active'); // show/hide menu
});
// Close menu when clicking a nav link
links.forEach(link => {
link.addEventListener('click', () => {
menuToggle.classList.remove('active'); // return to hamburger
navLinks.classList.remove('active'); // hide menu
});
});
// Header Scroll Effect
window.addEventListener('scroll', () => {
const header = document.getElementById('header');
if (header && window.scrollY > 100) {
header.classList.add('scrolled');
} else if (header) {
header.classList.remove('scrolled');
}
});
// Scroll Animations (Fade-in on View)
const observerOptions = {
threshold: 0.1,
rootMargin: '0px 0px -50px 0px'
};
const observer = new IntersectionObserver((entries) => {
entries.forEach(entry => {
if (entry.isIntersecting) {
entry.target.classList.add('visible');
}
});
}, observerOptions);
// Observe sections for animation
document.querySelectorAll('.page-section').forEach(section => {
observer.observe(section);
});
// Set active navigation link based on current page
function setActiveNavLink() {
const currentPage = window.location.pathname.split('/').pop() || 'index.html';
const navLinks = document.querySelectorAll('.nav-links a');
navLinks.forEach(link => {
const linkHref = link.getAttribute('href');
if (linkHref === currentPage ||
(currentPage === 'index.html' && linkHref === 'index.html') ||
(currentPage === '' && linkHref === 'index.html')) {
link.classList.add('active');
} else {
link.classList.remove('active');
}
});
}
const contactForm = document.getElementById('contactForm');
const formMsg = document.getElementById('formMsg');
if(contactForm){
contactForm.addEventListener('submit', (e)=>{
// let Formspree handle submission; show small feedback
formMsg.textContent = 'Sending...';
setTimeout(()=> formMsg.textContent = 'Thank you — your message was sent (Formspree).', 1200);
});
}
// Initialize when DOM is loaded
document.addEventListener('DOMContentLoaded', function() {
setActiveNavLink();
});
// Background Video Sound Toggle
document.addEventListener('DOMContentLoaded', () => {
const bgVideo = document.getElementById('bgVideo');
const soundBtn = document.getElementById('soundBtn');
if (bgVideo && soundBtn) {
soundBtn.addEventListener('click', () => {
if (bgVideo.muted) {
bgVideo.muted = false;
bgVideo.play();
soundBtn.textContent = '🔊';
} else {
bgVideo.muted = true;
soundBtn.textContent = '🔈';
}
});
}
});
document.addEventListener("DOMContentLoaded",function()
{
const btnAboutme = document.getElementById
('btn-aboutme');
const divAboutme = document.getElementById('info');
btnAboutme.addEventListener('click', function(){
if(divAboutme.classList.contains('hide')){
divAboutme.classList.remove('hide');
btnAboutme.textContent = "Hide About Me";
}else{
divAboutme.classList.add('hide');
btnAboutme.textContent = "More About Me";
}
});
});
// --- Typewriter Effect inside paragraph ---
const words = [" Website Developer", " Graphic Designer", " Coder"];
let i = 0;
let j = 0;
let currentWord = "";
let isDeleting = false;
const speed = 100;
const pause = 1000;
function type() {
const el = document.getElementById("changing-word");
if (!el) return;
const fullWord = words[i];
if (isDeleting) {
currentWord = fullWord.substring(0, j--);
} else {
currentWord = fullWord.substring(0, j++);
}
el.textContent = currentWord;
if (!isDeleting && j === fullWord.length + 1) {
isDeleting = true;
setTimeout(type, pause);
return;
}
if (isDeleting && j === 0) {
isDeleting = false;
i = (i + 1) % words.length;
}
setTimeout(type, isDeleting ? speed / 2 : speed);
}
type();