-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
90 lines (75 loc) · 2.9 KB
/
script.js
File metadata and controls
90 lines (75 loc) · 2.9 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
// Portfolio Website JavaScript
(function() {
'use strict';
// Smooth scroll for anchor links
document.querySelectorAll('a[href^="#"]').forEach(anchor => {
anchor.addEventListener('click', function (e) {
const href = this.getAttribute('href');
if (href === '#') return;
e.preventDefault();
const target = document.querySelector(href);
if (target) {
const navHeight = document.querySelector('.nav').offsetHeight;
const targetPosition = target.offsetTop - navHeight - 20;
window.scrollTo({
top: targetPosition,
behavior: 'smooth'
});
}
});
});
// Highlight active nav link on scroll
const sections = document.querySelectorAll('.section');
const navLinks = document.querySelectorAll('.nav-links a');
function highlightNav() {
const scrollPos = window.scrollY + 150;
sections.forEach((section, index) => {
const top = section.offsetTop;
const bottom = top + section.offsetHeight;
const id = section.getAttribute('id');
if (scrollPos >= top && scrollPos < bottom) {
navLinks.forEach(link => {
link.style.opacity = '0.5';
if (link.getAttribute('href') === `#${id}`) {
link.style.opacity = '1';
}
});
}
});
}
window.addEventListener('scroll', highlightNav);
highlightNav(); // Initial call
// Add loaded class for animations
window.addEventListener('load', function() {
document.body.classList.add('loaded');
});
// Intersection Observer for fade-in animations
const observerOptions = {
threshold: 0.1,
rootMargin: '0px 0px -50px 0px'
};
const observer = new IntersectionObserver(function(entries) {
entries.forEach(entry => {
if (entry.isIntersecting) {
entry.target.style.opacity = '1';
entry.target.style.transform = 'translateY(0)';
}
});
}, observerOptions);
// Observe timeline items and project cards
document.querySelectorAll('.timeline-item, .project-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', function(e) {
// ESC key to blur active element
if (e.key === 'Escape') {
document.activeElement.blur();
}
});
// Mobile menu toggle (if needed in future)
// Can be expanded for mobile hamburger menu
})();