-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
executable file
·226 lines (186 loc) · 7.21 KB
/
script.js
File metadata and controls
executable file
·226 lines (186 loc) · 7.21 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
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
// Wait for the DOM to be fully loaded
document.addEventListener('DOMContentLoaded', function () {
// Initialize AOS animations
AOS.init({
duration: 1000,
easing: 'ease-in-out',
once: true,
offset: 100
});
// Create stars for night sky effect
function createStars() {
const nightSky = document.querySelector('body.night-sky-body');
if (!nightSky) return;
const existing = nightSky.querySelector('.stars');
if (existing) {
existing.remove();
}
const starsContainer = document.createElement('div');
starsContainer.className = 'stars';
const isMobile = window.innerWidth < 768;
const starCount = isMobile ? 140 : 280;
for (let i = 0; i < starCount; i++) {
const star = document.createElement('div');
star.className = 'star';
// Random size
const sizes = ['small', 'medium', 'large'];
const randomSize = sizes[Math.floor(Math.random() * sizes.length)];
star.classList.add(randomSize);
// Random position
star.style.left = Math.random() * 100 + '%';
star.style.top = Math.random() * 100 + '%';
// Random animation delay
star.style.animationDelay = Math.random() * 3 + 's';
starsContainer.appendChild(star);
}
nightSky.appendChild(starsContainer);
}
// Create stars when page loads
createStars();
// Recreate stars on window resize for responsive design
window.addEventListener('resize', function () {
createStars();
});
// Navbar scroll effect
const navbar = document.querySelector('.navbar');
let lastScrollY = window.scrollY;
window.addEventListener('scroll', function () {
if (window.scrollY > 100) {
navbar.classList.add('scrolled');
} else {
navbar.classList.remove('scrolled');
}
// Hide/show navbar on scroll
if (window.scrollY > lastScrollY && window.scrollY > 100) {
navbar.style.transform = 'translateY(-100%)';
} else {
navbar.style.transform = 'translateY(0)';
}
lastScrollY = window.scrollY;
});
// Smooth scrolling for navigation links
document.querySelectorAll('a[href^="#"]').forEach(anchor => {
anchor.addEventListener('click', function (e) {
e.preventDefault();
const targetId = this.getAttribute('href');
const targetElement = document.querySelector(targetId);
if (targetElement) {
const navbarHeight = navbar.offsetHeight;
const targetPosition = targetElement.offsetTop - navbarHeight;
window.scrollTo({
top: targetPosition,
behavior: 'smooth'
});
}
});
});
// Back to top button
const backToTopButton = document.querySelector('.back-to-top');
if (backToTopButton) {
window.addEventListener('scroll', function () {
if (window.scrollY > 300) {
backToTopButton.classList.add('active');
} else {
backToTopButton.classList.remove('active');
}
});
backToTopButton.addEventListener('click', function (e) {
e.preventDefault();
window.scrollTo({
top: 0,
behavior: 'smooth'
});
});
}
// Skill progress animation
function animateSkillBars() {
const skillBars = document.querySelectorAll('.skill-progress');
const skillObserver = new IntersectionObserver(function (entries) {
entries.forEach(entry => {
if (entry.isIntersecting) {
const progressBar = entry.target;
const targetWidth = progressBar.getAttribute('data-width');
setTimeout(() => {
progressBar.style.width = targetWidth + '%';
}, 500);
skillObserver.unobserve(progressBar);
}
});
}, { threshold: 0.5 });
skillBars.forEach(bar => {
skillObserver.observe(bar);
});
}
// Initialize skill bar animations
animateSkillBars();
// Add typing effect to job title
const jobTitle = document.querySelector('.hero-section .text-primary');
if (jobTitle) {
const originalText = jobTitle.textContent;
jobTitle.textContent = '';
let i = 0;
const typeWriter = () => {
if (i < originalText.length) {
jobTitle.textContent += originalText.charAt(i);
i++;
setTimeout(typeWriter, 100);
}
};
// Start typing effect after initial animations
setTimeout(typeWriter, 1500);
}
// Parallax effect for hero section
window.addEventListener('scroll', function () {
const scrolled = window.pageYOffset;
const rate = scrolled * -0.5;
const heroSection = document.querySelector('.hero-section');
if (heroSection && scrolled < heroSection.offsetHeight) {
heroSection.style.transform = `translateY(${rate}px)`;
}
});
// Project card hover effects
const projectCards = document.querySelectorAll('.project-card');
projectCards.forEach(card => {
card.addEventListener('mouseenter', function () {
this.style.transform = 'translateY(-10px) rotateY(5deg)';
});
card.addEventListener('mouseleave', function () {
this.style.transform = 'translateY(0) rotateY(0)';
});
});
// Testimonial carousel auto-scroll (if you want to add this later)
// You can implement a carousel system here if needed
// Contact form enhancement (if you add a contact form later)
const contactForm = document.querySelector('#contact-form');
if (contactForm) {
contactForm.addEventListener('submit', function (e) {
e.preventDefault();
// Add form submission logic here
alert('Thank you for your message! I\'ll get back to you soon.');
});
}
// Loading animation
window.addEventListener('load', function () {
document.body.classList.add('loaded');
});
// Intersection Observer for general 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.classList.add('visible');
}
});
}, observerOptions);
// Observe elements for scroll animations
document.querySelectorAll('.fade-in-on-scroll').forEach(el => {
observer.observe(el);
});
// Console message for developers
console.log('%c👋 Hello there, fellow developer!', 'color: #13233c; font-size: 16px; font-weight: bold;');
console.log('%cInterested in how this portfolio was built? Check out the code on GitHub!', 'color: #666; font-size: 14px;');
console.log('%chttps://github.com/Silas-Matabane', 'color: #0066cc; font-size: 14px;');
});