Repository navigation
Expand file tree
/
Copy pathscript.js
More file actions
121 lines (101 loc) · 4.01 KB
/
Copy pathscript.js
File metadata and controls
121 lines (101 loc) · 4.01 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
// Wait for the DOM to be fully loaded
document.addEventListener('DOMContentLoaded', function() {
// Smooth scrolling for navigation links
const navLinks = document.querySelectorAll('nav a[href^="#"]');
navLinks.forEach(link => {
link.addEventListener('click', function(e) {
e.preventDefault();
const targetId = this.getAttribute('href');
const targetElement = document.querySelector(targetId);
if (targetElement) {
window.scrollTo({
top: targetElement.offsetTop - 70, // Account for fixed header
behavior: 'smooth'
});
// Update active nav link
navLinks.forEach(link => link.classList.remove('active'));
this.classList.add('active');
}
});
});
// Highlight active section on scroll
const sections = document.querySelectorAll('section');
function highlightNavOnScroll() {
const scrollPosition = window.scrollY;
sections.forEach(section => {
const sectionTop = section.offsetTop - 100;
const sectionBottom = sectionTop + section.offsetHeight;
const sectionId = section.getAttribute('id');
if (scrollPosition >= sectionTop && scrollPosition < sectionBottom) {
navLinks.forEach(link => {
link.classList.remove('active');
if (link.getAttribute('href') === `#${sectionId}`) {
link.classList.add('active');
}
});
}
});
}
// Initial call to highlight the correct section
highlightNavOnScroll();
// Throttle scroll event to improve performance
let isScrolling = false;
window.addEventListener('scroll', function() {
if (!isScrolling) {
window.requestAnimationFrame(function() {
highlightNavOnScroll();
isScrolling = false;
});
isScrolling = true;
}
});
// Add animation to cards and elements when they come into view
const animatedElements = document.querySelectorAll('.strength-card, .project-card, .timeline-item, .blog-card');
// Create Intersection Observer
const observer = new IntersectionObserver((entries) => {
entries.forEach(entry => {
if (entry.isIntersecting) {
entry.target.classList.add('animate-in');
observer.unobserve(entry.target); // Stop observing once animated
}
});
}, {
threshold: 0.2 // Trigger when 20% of the element is visible
});
// Add initial hidden class and then observe
animatedElements.forEach(element => {
element.classList.add('hidden-element');
observer.observe(element);
});
// Add CSS for animations
const style = document.createElement('style');
style.textContent = `
.hidden-element {
opacity: 0;
transform: translateY(20px);
transition: none;
}
.animate-in {
opacity: 1;
transform: translateY(0);
transition: opacity 0.6s ease-out, transform 0.6s ease-out;
}
`;
document.head.appendChild(style);
// Add typing effect to the header tagline
const taglineElement = document.querySelector('.header-content p');
if (taglineElement) {
const originalText = taglineElement.textContent;
taglineElement.textContent = '';
let i = 0;
const typeWriter = () => {
if (i < originalText.length) {
taglineElement.textContent += originalText.charAt(i);
i++;
setTimeout(typeWriter, 50); // Adjust typing speed here
}
};
// Start typing effect after a short delay
setTimeout(typeWriter, 500);
}
});