-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathscript.js
More file actions
142 lines (124 loc) · 4.7 KB
/
Copy pathscript.js
File metadata and controls
142 lines (124 loc) · 4.7 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
// Smooth scroll reveal animations
const observerOptions = {
threshold: 0.1,
rootMargin: '0px 0px -100px 0px'
};
const observer = new IntersectionObserver((entries) => {
entries.forEach(entry => {
if (entry.isIntersecting) {
entry.target.classList.add('visible');
}
});
}, observerOptions);
// Observe all sections
document.addEventListener('DOMContentLoaded', () => {
const sections = document.querySelectorAll('.section');
sections.forEach(section => {
observer.observe(section);
});
// Smooth scroll for anchor links
document.querySelectorAll('a[href^="#"]').forEach(anchor => {
anchor.addEventListener('click', function (e) {
e.preventDefault();
const target = document.querySelector(this.getAttribute('href'));
if (target) {
const navHeight = document.querySelector('.navbar').offsetHeight;
const targetPosition = target.offsetTop - navHeight;
window.scrollTo({
top: targetPosition,
behavior: 'smooth'
});
}
});
});
// Terminal typing effect
const terminalOutput = document.querySelector('.terminal-body');
if (terminalOutput) {
const outputs = terminalOutput.querySelectorAll('.output');
outputs.forEach((output, index) => {
output.style.opacity = '0';
setTimeout(() => {
output.style.transition = 'opacity 0.3s ease';
output.style.opacity = '1';
}, 800 + (index * 300));
});
}
// Add active state to nav links based on scroll position
const navLinks = document.querySelectorAll('.nav-menu a');
window.addEventListener('scroll', () => {
let current = '';
const sections = document.querySelectorAll('.section');
sections.forEach(section => {
const sectionTop = section.offsetTop;
const sectionHeight = section.clientHeight;
if (window.pageYOffset >= sectionTop - 200) {
current = section.getAttribute('id');
}
});
navLinks.forEach(link => {
link.classList.remove('active');
if (link.getAttribute('href') === `#${current}`) {
link.classList.add('active');
}
});
});
// Parallax effect for grid background
let ticking = false;
window.addEventListener('scroll', () => {
if (!ticking) {
window.requestAnimationFrame(() => {
const scrolled = window.pageYOffset;
const gridBg = document.querySelector('.grid-background');
if (gridBg) {
gridBg.style.transform = `translateY(${scrolled * 0.5}px)`;
}
ticking = false;
});
ticking = true;
}
});
// Lightbox functionality
const lightbox = document.getElementById('lightbox');
const lightboxImg = document.getElementById('lightbox-img');
const lightboxClose = document.getElementById('lightbox-close');
const blogImages = document.querySelectorAll('.blog-image');
// Open lightbox when clicking on blog images
blogImages.forEach(img => {
img.addEventListener('click', () => {
lightbox.classList.add('active');
lightboxImg.src = img.src;
lightboxImg.alt = img.alt;
document.body.style.overflow = 'hidden'; // Prevent scrolling
});
});
// Close lightbox when clicking close button
lightboxClose.addEventListener('click', () => {
lightbox.classList.remove('active');
document.body.style.overflow = ''; // Restore scrolling
});
// Close lightbox when clicking outside the image
lightbox.addEventListener('click', (e) => {
if (e.target === lightbox) {
lightbox.classList.remove('active');
document.body.style.overflow = ''; // Restore scrolling
}
});
// Close lightbox with Escape key
document.addEventListener('keydown', (e) => {
if (e.key === 'Escape' && lightbox.classList.contains('active')) {
lightbox.classList.remove('active');
document.body.style.overflow = ''; // Restore scrolling
}
});
});
// Add cursor trail effect (optional - can be removed if too much)
let cursorTrail = [];
const trailLength = 10;
document.addEventListener('mousemove', (e) => {
if (window.innerWidth > 768) { // Only on desktop
cursorTrail.push({ x: e.clientX, y: e.clientY });
if (cursorTrail.length > trailLength) {
cursorTrail.shift();
}
}
});