-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
196 lines (194 loc) · 8.05 KB
/
script.js
File metadata and controls
196 lines (194 loc) · 8.05 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
// Add smooth scroll and contact form feedback
document.addEventListener('DOMContentLoaded', function() {
// Smooth scroll for nav links and active link highlight
const navLinks = document.querySelectorAll('nav a');
navLinks.forEach(link => {
link.addEventListener('click', function(e) {
const target = document.querySelector(this.getAttribute('href'));
if (target) {
e.preventDefault();
target.scrollIntoView({ behavior: 'smooth' });
}
});
});
// Highlight nav link on scroll
const sections = document.querySelectorAll('section');
window.addEventListener('scroll', function() {
let current = '';
sections.forEach(section => {
const sectionTop = section.offsetTop - 80;
if (pageYOffset >= sectionTop) {
current = section.getAttribute('id');
}
});
navLinks.forEach(link => {
link.classList.remove('active');
if (link.getAttribute('href') === '#' + current) {
link.classList.add('active');
}
});
});
// Enhanced nav highlight on scroll for all sections
const sectionIds = [
'about',
'skills',
'services',
'portfolio',
'projects',
'mainpages',
'disclaimers'
];
function highlightNavOnScroll() {
let scrollPos = window.scrollY || window.pageYOffset;
let found = false;
for (let i = sectionIds.length - 1; i >= 0; i--) {
const section = document.getElementById(sectionIds[i]);
if (section) {
const offset = section.offsetTop - 120;
if (scrollPos >= offset) {
navLinks.forEach(link => link.classList.remove('active'));
const activeLink = document.querySelector(`nav ul li a[href="#${sectionIds[i]}"]`);
if (activeLink) activeLink.classList.add('active');
found = true;
break;
}
}
}
if (!found) navLinks.forEach(link => link.classList.remove('active'));
}
window.addEventListener('scroll', highlightNavOnScroll);
document.addEventListener('DOMContentLoaded', highlightNavOnScroll);
// Portfolio item tilt effect
document.querySelectorAll('.portfolio-item').forEach(item => {
item.addEventListener('mousemove', function(e) {
const rect = item.getBoundingClientRect();
const x = e.clientX - rect.left;
const y = e.clientY - rect.top;
const centerX = rect.width / 2;
const centerY = rect.height / 2;
const rotateX = ((y - centerY) / centerY) * 8;
const rotateY = ((x - centerX) / centerX) * -8;
item.style.transform = `rotateX(${rotateX}deg) rotateY(${rotateY}deg) scale(1.04)`;
});
item.addEventListener('mouseleave', function() {
item.style.transform = '';
});
});
// Contact form feedback
const form = document.getElementById('contact-form');
if (form) {
form.addEventListener('submit', function(e) {
e.preventDefault();
form.reset();
const msg = document.createElement('div');
msg.textContent = 'Thank you for reaching out! I will get back to you soon.';
msg.style.background = 'linear-gradient(90deg,#00c3ff,#b2fefa)';
msg.style.color = '#232526';
msg.style.padding = '1rem';
msg.style.borderRadius = '8px';
msg.style.marginTop = '1rem';
msg.style.textAlign = 'center';
form.parentNode.appendChild(msg);
setTimeout(() => msg.remove(), 3500);
});
}
function openPage(url) {
window.open(url, '_blank');
}
// Add scroll-triggered animation for .master > .fade-item in Projects, Main Pages, and Disclaimers
function animateOnScroll(sectionId) {
const section = document.getElementById(sectionId);
if (!section) return;
const master = section.querySelector('.master');
if (!master) return;
const items = master.querySelectorAll('.fade-item');
let animated = false;
function onScroll() {
if (animated) return;
const rect = section.getBoundingClientRect();
if (rect.top < window.innerHeight - 80) {
items.forEach(item => item.classList.add('animated'));
animated = true;
window.removeEventListener('scroll', onScroll);
}
}
window.addEventListener('scroll', onScroll);
onScroll(); // in case already in view
}
animateOnScroll('projects');
animateOnScroll('mainpages');
animateOnScroll('disclaimers');
// Make .master > .fade-item clickable for Projects, Main Pages, Disclaimers
function makeMasterDivsClickable(sectionId) {
const section = document.getElementById(sectionId);
if (!section) return;
const master = section.querySelector('.master');
if (!master) return;
master.querySelectorAll('.fade-item').forEach(div => {
const h1 = div.querySelector('h1');
if (h1 && h1.hasAttribute('onclick')) {
const handler = h1.getAttribute('onclick');
div.style.cursor = 'pointer';
div.onclick = function(e) {
// Prevent double navigation if h1 is clicked
if (e.target === h1) return;
// Evaluate the onclick handler (openPage(...))
eval(handler);
};
}
});
}
makeMasterDivsClickable('projects');
makeMasterDivsClickable('mainpages');
makeMasterDivsClickable('disclaimers');
// Typing animation for About Me
const aboutText = "Creative DJ, virtualization enthusiast, and passionate gamer. I blend music, technology, building virtual environments, and competitive gaming. Always exploring the latest in music tech, virtual machines, and gaming trends.";
const aboutElem = document.getElementById('about-typed');
let aboutIdx = 0;
function typeAbout() {
if (aboutElem && aboutIdx < aboutText.length) {
aboutElem.textContent += aboutText.charAt(aboutIdx);
aboutIdx++;
setTimeout(typeAbout, 25);
}
}
typeAbout();
// Back to Top button logic
const backToTopBtn = document.getElementById('backToTop');
window.addEventListener('scroll', function() {
if (window.scrollY > 300) {
backToTopBtn.style.display = 'block';
} else {
backToTopBtn.style.display = 'none';
}
});
backToTopBtn.addEventListener('click', function() {
window.scrollTo({ top: 0, behavior: 'smooth' });
});
// Nav scroll tracker to highlight active section
(function() {
const navLinks = document.querySelectorAll('nav a');
const sections = Array.from(document.querySelectorAll('section'));
function highlightNavOnScroll() {
let current = '';
const scrollPos = window.scrollY + 120;
for (let i = 0; i < sections.length; i++) {
if (scrollPos >= sections[i].offsetTop) {
current = sections[i].getAttribute('id');
}
}
// If at the very top, highlight 'about'
if (window.scrollY < sections[0].offsetTop + 50) {
current = 'about';
}
navLinks.forEach(link => {
link.classList.remove('active');
if (link.getAttribute('href') === '#' + current) {
link.classList.add('active');
}
});
}
window.addEventListener('scroll', highlightNavOnScroll);
highlightNavOnScroll(); // Run on load
})();
});