-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
138 lines (120 loc) · 4.42 KB
/
Copy pathscript.js
File metadata and controls
138 lines (120 loc) · 4.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
// Mobile Navigation Toggle
const hamburger = document.querySelector('.hamburger');
const navMenu = document.querySelector('.nav-menu');
hamburger.addEventListener('click', () => {
navMenu.classList.toggle('active');
hamburger.classList.toggle('active');
});
// Close mobile menu when clicking on a link
document.querySelectorAll('.nav-link').forEach(link => {
link.addEventListener('click', () => {
navMenu.classList.remove('active');
hamburger.classList.remove('active');
});
});
// Smooth Scrolling
document.querySelectorAll('a[href^="#"]').forEach(anchor => {
anchor.addEventListener('click', function (e) {
e.preventDefault();
const target = document.querySelector(this.getAttribute('href'));
if (target) {
target.scrollIntoView({
behavior: 'smooth',
block: 'start'
});
}
});
});
// Navbar Background on Scroll
window.addEventListener('scroll', () => {
const navbar = document.querySelector('.navbar');
if (window.scrollY > 50) {
navbar.style.boxShadow = '0 4px 6px -1px rgba(0, 0, 0, 0.1)';
} else {
navbar.style.boxShadow = '0 4px 6px -1px rgba(0, 0, 0, 0.1)';
}
});
// Animate Skill Bars on Scroll
const observerOptions = {
threshold: 0.5,
rootMargin: '0px'
};
const observer = new IntersectionObserver((entries) => {
entries.forEach(entry => {
if (entry.isIntersecting) {
const skillProgress = entry.target.querySelector('.skill-progress');
const width = skillProgress.getAttribute('data-width');
skillProgress.style.width = width + '%';
observer.unobserve(entry.target);
}
});
}, observerOptions);
document.querySelectorAll('.skill-card').forEach(card => {
observer.observe(card);
});
// Animate Elements on Scroll
const animateOnScroll = new IntersectionObserver((entries) => {
entries.forEach(entry => {
if (entry.isIntersecting) {
entry.target.style.opacity = '1';
entry.target.style.transform = 'translateY(0)';
}
});
}, {
threshold: 0.1
});
// Apply animation to sections
document.querySelectorAll('.about-content, .skills-grid, .projects-grid, .contact-content').forEach(section => {
section.style.opacity = '0';
section.style.transform = 'translateY(30px)';
section.style.transition = 'opacity 0.6s ease, transform 0.6s ease';
animateOnScroll.observe(section);
});
// Form Submission
const contactForm = document.querySelector('.contact-form');
if (contactForm) {
contactForm.addEventListener('submit', (e) => {
e.preventDefault();
// Get form data
const formData = new FormData(contactForm);
const name = contactForm.querySelector('input[type="text"]').value;
const email = contactForm.querySelector('input[type="email"]').value;
const subject = contactForm.querySelectorAll('input[type="text"]')[1].value;
const message = contactForm.querySelector('textarea').value;
// Here you would typically send the data to a server
// For now, we'll just show an alert
alert(`Thank you for your message, ${name}! I'll get back to you soon.`);
// Reset form
contactForm.reset();
});
}
// Active Navigation Link Highlighting
window.addEventListener('scroll', () => {
const sections = document.querySelectorAll('section[id]');
const scrollY = window.pageYOffset;
sections.forEach(section => {
const sectionHeight = section.offsetHeight;
const sectionTop = section.offsetTop - 100;
const sectionId = section.getAttribute('id');
const navLink = document.querySelector(`.nav-link[href="#${sectionId}"]`);
if (scrollY > sectionTop && scrollY <= sectionTop + sectionHeight) {
document.querySelectorAll('.nav-link').forEach(link => {
link.classList.remove('active');
});
if (navLink) {
navLink.classList.add('active');
}
}
});
});
// Add active class styling
const style = document.createElement('style');
style.textContent = `
.nav-link.active {
color: var(--primary-color);
}
.nav-link.active::after {
width: 100%;
}
`;
document.head.appendChild(style);