-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
192 lines (163 loc) · 5.42 KB
/
script.js
File metadata and controls
192 lines (163 loc) · 5.42 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
// Theme Toggle
const themeToggle = document.getElementById('themeToggle');
const html = document.documentElement;
// Load saved theme or default to dark
const savedTheme = localStorage.getItem('theme') || 'dark';
html.setAttribute('data-theme', savedTheme);
themeToggle.addEventListener('click', () => {
const currentTheme = html.getAttribute('data-theme');
const newTheme = currentTheme === 'dark' ? 'light' : 'dark';
html.setAttribute('data-theme', newTheme);
localStorage.setItem('theme', newTheme);
// Add rotation animation
themeToggle.style.transform = 'rotate(360deg)';
setTimeout(() => {
themeToggle.style.transform = 'rotate(0deg)';
}, 300);
});
// Page Navigation
const navLinks = document.querySelectorAll('.nav-link');
const pages = document.querySelectorAll('.page');
function showPage(pageId) {
// Hide all pages
pages.forEach(page => {
page.classList.remove('active');
});
// Show selected page
const targetPage = document.getElementById(pageId);
if (targetPage) {
targetPage.classList.add('active');
}
// Update active nav link
navLinks.forEach(link => {
link.classList.remove('active');
if (link.getAttribute('data-page') === pageId) {
link.classList.add('active');
}
});
// Update URL hash
window.location.hash = pageId;
// Scroll to top
window.scrollTo({ top: 0, behavior: 'smooth' });
}
// Handle navigation clicks
navLinks.forEach(link => {
link.addEventListener('click', (e) => {
e.preventDefault();
const pageId = link.getAttribute('data-page');
showPage(pageId);
});
});
// Handle initial page load with hash
window.addEventListener('DOMContentLoaded', () => {
const hash = window.location.hash.substring(1);
if (hash && document.getElementById(hash)) {
showPage(hash);
} else {
showPage('home');
}
});
// Handle browser back/forward
window.addEventListener('hashchange', () => {
const hash = window.location.hash.substring(1);
if (hash && document.getElementById(hash)) {
showPage(hash);
}
});
// Smooth scroll for anchor links
document.querySelectorAll('a[href^="#"]').forEach(anchor => {
anchor.addEventListener('click', function (e) {
const href = this.getAttribute('href');
if (href !== '#' && !this.classList.contains('nav-link')) {
e.preventDefault();
const target = document.querySelector(href);
if (target) {
target.scrollIntoView({
behavior: 'smooth',
block: 'start'
});
}
}
});
});
// Add parallax effect to hero section (subtle)
window.addEventListener('scroll', () => {
const scrolled = window.pageYOffset;
const hero = document.querySelector('.hero');
if (hero && scrolled < window.innerHeight) {
hero.style.transform = `translateY(${scrolled * 0.3}px)`;
hero.style.opacity = 1 - (scrolled / window.innerHeight) * 0.5;
}
});
// Add intersection observer for fade-in animations
const observerOptions = {
threshold: 0.1,
rootMargin: '0px 0px -100px 0px'
};
const observer = new IntersectionObserver((entries) => {
entries.forEach(entry => {
if (entry.isIntersecting) {
entry.target.style.opacity = '1';
entry.target.style.transform = 'translateY(0)';
}
});
}, observerOptions);
// Observe elements with fade-in class
document.querySelectorAll('.project-card, .skill-category, .blog-post, .note-card').forEach(el => {
el.style.opacity = '0';
el.style.transform = 'translateY(20px)';
el.style.transition = 'opacity 0.6s ease, transform 0.6s ease';
observer.observe(el);
});
// Keyboard navigation
document.addEventListener('keydown', (e) => {
// Press 'T' to toggle theme
if (e.key === 't' || e.key === 'T') {
if (document.activeElement.tagName !== 'INPUT' &&
document.activeElement.tagName !== 'TEXTAREA') {
themeToggle.click();
}
}
// Press numbers 1-4 to navigate to pages
const pageMap = {
'1': 'home',
'2': 'about',
'3': 'blog',
'4': 'notes'
};
if (pageMap[e.key]) {
if (document.activeElement.tagName !== 'INPUT' &&
document.activeElement.tagName !== 'TEXTAREA') {
showPage(pageMap[e.key]);
}
}
});
// Add easter egg: Konami code
let konamiCode = [];
const konamiSequence = ['ArrowUp', 'ArrowUp', 'ArrowDown', 'ArrowDown', 'ArrowLeft', 'ArrowRight', 'ArrowLeft', 'ArrowRight', 'b', 'a'];
document.addEventListener('keydown', (e) => {
konamiCode.push(e.key);
konamiCode = konamiCode.slice(-10);
if (konamiCode.join(',') === konamiSequence.join(',')) {
const hero = document.querySelector('.hero-title');
if (hero) {
hero.style.animation = 'glitch 0.3s infinite';
setTimeout(() => {
hero.style.animation = '';
}, 3000);
}
console.log('🎮 Cheat code activated!');
}
});
// Console message
console.log(`
%c👋 Hello there!
%cLooks like you're checking out the source.
Feel free to explore the code on GitHub.
Press 'T' to toggle theme
Press 1-4 to navigate pages
Built with vanilla JS, no frameworks needed.
`,
'font-size: 24px; font-weight: bold; color: #00ff88;',
'font-size: 14px; color: #a0a0a0;'
);