-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
173 lines (156 loc) · 4.98 KB
/
script.js
File metadata and controls
173 lines (156 loc) · 4.98 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
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
// 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
const navbar = document.querySelector('.navbar');
window.addEventListener('scroll', () => {
if (window.scrollY > 50) {
navbar.style.background = 'rgba(255, 255, 255, 0.98)';
navbar.style.boxShadow = '0 4px 15px rgba(0, 0, 0, 0.1)';
} else {
navbar.style.background = 'rgba(255, 255, 255, 0.95)';
navbar.style.boxShadow = '0 2px 10px rgba(0, 0, 0, 0.05)';
}
});
// Hamburger Menu Toggle
const hamburger = document.querySelector('.hamburger');
const navMenu = document.querySelector('.nav-menu');
if (hamburger) {
hamburger.addEventListener('click', () => {
navMenu.style.display = navMenu.style.display === 'flex' ? 'none' : 'flex';
hamburger.classList.toggle('active');
});
}
// Intersection Observer for Animations
const observerOptions = {
threshold: 0.1,
rootMargin: '0px 0px -100px 0px'
};
const observer = new IntersectionObserver((entries) => {
entries.forEach(entry => {
if (entry.isIntersecting) {
entry.target.style.opacity = '1';
entry.target.style.transform = 'translateY(0)';
}
});
}, observerOptions);
// Observe all sections
document.querySelectorAll('section').forEach(section => {
section.style.opacity = '0';
section.style.transform = 'translateY(20px)';
section.style.transition = 'all 0.6s ease';
observer.observe(section);
});
// Animate skill items on scroll
const skillItems = document.querySelectorAll('.skill-item');
const skillObserver = new IntersectionObserver((entries) => {
entries.forEach((entry, index) => {
if (entry.isIntersecting) {
setTimeout(() => {
entry.target.style.opacity = '1';
entry.target.style.transform = 'scale(1)';
}, index * 50);
}
});
}, { threshold: 0.1 });
skillItems.forEach(item => {
item.style.opacity = '0';
item.style.transform = 'scale(0.8)';
item.style.transition = 'all 0.3s ease';
skillObserver.observe(item);
});
// Animate project cards
const projectCards = document.querySelectorAll('.project-card');
const projectObserver = new IntersectionObserver((entries) => {
entries.forEach((entry, index) => {
if (entry.isIntersecting) {
setTimeout(() => {
entry.target.style.opacity = '1';
entry.target.style.transform = 'translateY(0)';
}, index * 100);
}
});
}, { threshold: 0.1 });
projectCards.forEach(card => {
card.style.opacity = '0';
card.style.transform = 'translateY(20px)';
card.style.transition = 'all 0.6s ease';
projectObserver.observe(card);
});
// Scroll to top button
const scrollTop = () => {
window.scrollTo({ top: 0, behavior: 'smooth' });
};
// Add scroll top button on page
window.addEventListener('scroll', () => {
if (window.scrollY > 300) {
if (!document.querySelector('.scroll-top-btn')) {
const btn = document.createElement('button');
btn.className = 'scroll-top-btn';
btn.innerHTML = '<i class="fas fa-arrow-up"></i>';
btn.onclick = scrollTop;
document.body.appendChild(btn);
}
} else {
const btn = document.querySelector('.scroll-top-btn');
if (btn) btn.remove();
}
});
// Parallax effect for hero section
const hero = document.querySelector('.hero');
window.addEventListener('scroll', () => {
if (hero) {
const scrollPosition = window.scrollY;
hero.style.backgroundPosition = `0 ${scrollPosition * 0.5}px`;
}
});
// Add styles for scroll-top-btn dynamically
const style = document.createElement('style');
style.textContent = `
.scroll-top-btn {
position: fixed;
bottom: 2rem;
right: 2rem;
width: 50px;
height: 50px;
background: linear-gradient(135deg, #6366f1, #4f46e5);
color: white;
border: none;
border-radius: 50%;
cursor: pointer;
display: flex;
align-items: center;
justify-content: center;
font-size: 1.2rem;
box-shadow: 0 10px 30px rgba(0, 0, 0, 0.1);
animation: slideUp 0.3s ease;
z-index: 999;
transition: all 0.3s ease;
}
.scroll-top-btn:hover {
transform: translateY(-5px);
box-shadow: 0 15px 40px rgba(0, 0, 0, 0.2);
}
@keyframes slideUp {
from {
transform: translateY(100px);
opacity: 0;
}
to {
transform: translateY(0);
opacity: 1;
}
}
`;
document.head.appendChild(style);
console.log('Portfolio website loaded successfully!');