-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
142 lines (121 loc) · 4.74 KB
/
script.js
File metadata and controls
142 lines (121 loc) · 4.74 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
document.addEventListener('DOMContentLoaded', function() {
// Mobile Menu Toggle
const mobileMenuBtn = document.querySelector('.mobile-menu-btn');
const nav = document.querySelector('.nav');
const navLinks = document.querySelectorAll('.nav-link');
const navOverlay = document.querySelector('.nav-overlay');
function closeMenu() {
if (nav && mobileMenuBtn) {
nav.classList.remove('active');
mobileMenuBtn.classList.remove('active');
mobileMenuBtn.textContent = '☰';
}
}
if (mobileMenuBtn && nav) {
mobileMenuBtn.addEventListener('click', function() {
const isActive = nav.classList.contains('active');
nav.classList.toggle('active');
this.textContent = isActive ? '☰' : '✕';
if (!isActive) {
navLinks.forEach(link => {
link.addEventListener('click', closeMenu, { once: true });
});
}
});
}
// Close Menu on Outside Click
document.addEventListener('click', function(e) {
if (nav && mobileMenuBtn && !e.target.closest('.header')) {
closeMenu();
}
});
// Close Mobile Menu on Escape Key
document.addEventListener('keydown', function(e) {
if (e.key === 'Escape' && nav && nav.classList.contains('active')) {
closeMenu();
}
});
// Smooth Scroll for Anchor Links
document.querySelectorAll('a[href^="#"]').forEach(anchor => {
anchor.addEventListener('click', function(e) {
const targetId = this.getAttribute('href');
if (targetId === '#') return;
const target = document.querySelector(targetId);
if (target) {
e.preventDefault();
const headerHeight = document.querySelector('.header').offsetHeight;
const targetPosition = target.offsetTop - headerHeight;
window.scrollTo({
top: targetPosition,
behavior: 'smooth'
});
}
});
});
// Header Background on Scroll
const header = document.querySelector('.header');
if (header) {
window.addEventListener('scroll', function() {
if (window.scrollY > 50) {
header.style.backgroundColor = 'rgba(10, 10, 10, 0.7)';
header.style.backgroundFilter = 'blur(10px)'
} else {
header.style.backgroundColor = 'rgba(10, 10, 10, 0.7)';
header.style.backgroundFilter = 'blur(10px)'
}
});
}
// Active Navigation Link on Scroll
const sections = document.querySelectorAll('section[id]');
if (sections.length > 0) {
window.addEventListener('scroll', function() {
const scrollY = window.scrollY + 100;
sections.forEach(section => {
const sectionHeight = section.offsetHeight;
const sectionTop = section.offsetTop;
const sectionId = section.getAttribute('id');
if (scrollY > sectionTop && scrollY <= sectionTop + sectionHeight) {
navLinks.forEach(link => {
link.classList.remove('active');
if (link.getAttribute('href') === `#${sectionId}`) {
link.classList.add('active');
}
});
}
});
});
}
// Animation on Scroll
const observerOptions = {
threshold: 0.1,
rootMargin: '0px 0px -50px 0px'
};
const observer = new IntersectionObserver(function(entries) {
entries.forEach(entry => {
if (entry.isIntersecting) {
entry.target.classList.add('animate-in');
}
});
}, observerOptions);
// Add animation class to cards
const cards = document.querySelectorAll('.skill-card, .project-card, .review-card');
cards.forEach(card => {
card.style.opacity = '0';
card.style.transform = 'translateY(20px)';
card.style.transition = 'opacity 0.6s ease, transform 0.6s ease';
observer.observe(card);
});
// Add CSS for animation
const style = document.createElement('style');
style.textContent = `
.animate-in {
opacity: 1 !important;
transform: translateY(0) !important;
}
`;
document.head.appendChild(style);
});
// Console Info
console.log('%cPortfolio Website Loaded', 'color: #3b82f6; font-size: 16px; font-weight: bold;');
console.log('%c/ᐠ。ꞈ。ᐟ\\', 'color: #888; font-size: 12px;');
console.log('%cwith ❤️', 'color: #888; font-size: 12px;');