-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
262 lines (222 loc) · 7.96 KB
/
script.js
File metadata and controls
262 lines (222 loc) · 7.96 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
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
// Mobile Navigation Toggle
const navToggle = document.querySelector('.nav-toggle');
const navMenu = document.querySelector('.nav-menu');
navToggle.addEventListener('click', () => {
navMenu.classList.toggle('active');
// Animate hamburger menu
const spans = navToggle.querySelectorAll('span');
if (navMenu.classList.contains('active')) {
spans[0].style.transform = 'rotate(45deg) translate(5px, 5px)';
spans[1].style.opacity = '0';
spans[2].style.transform = 'rotate(-45deg) translate(7px, -6px)';
} else {
spans[0].style.transform = 'none';
spans[1].style.opacity = '1';
spans[2].style.transform = 'none';
}
});
// Close mobile menu when clicking on a link
navMenu.addEventListener('click', (e) => {
if (e.target.tagName === 'A') {
navMenu.classList.remove('active');
const spans = navToggle.querySelectorAll('span');
spans[0].style.transform = 'none';
spans[1].style.opacity = '1';
spans[2].style.transform = 'none';
}
});
// Header scroll effect
const header = document.querySelector('.header');
let lastScrollY = window.scrollY;
window.addEventListener('scroll', () => {
const currentScrollY = window.scrollY;
if (currentScrollY > 100) {
header.style.background = 'rgba(255, 255, 255, 0.98)';
header.style.boxShadow = '0 2px 20px rgba(0, 0, 0, 0.1)';
} else {
header.style.background = 'rgba(255, 255, 255, 0.95)';
header.style.boxShadow = 'none';
}
// Hide/show header on scroll
if (currentScrollY > lastScrollY && currentScrollY > 200) {
header.style.transform = 'translateY(-100%)';
} else {
header.style.transform = 'translateY(0)';
}
lastScrollY = currentScrollY;
});
// Smooth scrolling for anchor links
document.querySelectorAll('a[href^="#"]').forEach(anchor => {
anchor.addEventListener('click', function (e) {
e.preventDefault();
const target = document.querySelector(this.getAttribute('href'));
if (target) {
const headerHeight = header.offsetHeight;
const targetPosition = target.offsetTop - headerHeight - 20;
window.scrollTo({
top: targetPosition,
behavior: 'smooth'
});
}
});
});
// Form submission
const contactForm = document.querySelector('.contact-form');
contactForm.addEventListener('submit', function(e) {
e.preventDefault();
// Get form data
const formData = new FormData(this);
const data = Object.fromEntries(formData);
// Simple validation
if (!data.name || !data.email || !data.message) {
alert('Будь ласка, заповніть всі обов\'язкові поля');
return;
}
// Email validation
const emailRegex = /^[^\s@]+@[^\s@]+\.[^\s@]+$/;
if (!emailRegex.test(data.email)) {
alert('Будь ласка, введіть коректний email');
return;
}
// Simulate form submission
const submitBtn = this.querySelector('button[type="submit"]');
const originalText = submitBtn.textContent;
submitBtn.textContent = 'Відправляється...';
submitBtn.disabled = true;
setTimeout(() => {
alert('Дякую за повідомлення! Я зв\'яжуся з вами найближчим часом.');
this.reset();
submitBtn.textContent = originalText;
submitBtn.disabled = false;
}, 2000);
});
// Intersection Observer for animations
const observerOptions = {
threshold: 0.1,
rootMargin: '0px 0px -50px 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 elements for animation
document.querySelectorAll('.service-card, .tech-category, .portfolio-item').forEach(el => {
el.style.opacity = '0';
el.style.transform = 'translateY(30px)';
el.style.transition = 'opacity 0.6s ease, transform 0.6s ease';
observer.observe(el);
});
// Typing effect for hero title
const heroTitle = document.querySelector('.hero-title');
if (heroTitle) {
const text = heroTitle.innerHTML;
heroTitle.innerHTML = '';
let i = 0;
const typeWriter = () => {
if (i < text.length) {
heroTitle.innerHTML += text.charAt(i);
i++;
setTimeout(typeWriter, 50);
}
};
// Start typing effect after a short delay
setTimeout(typeWriter, 500);
}
// Parallax effect for hero section
window.addEventListener('scroll', () => {
const scrolled = window.pageYOffset;
const hero = document.querySelector('.hero');
const codeWindow = document.querySelector('.code-window');
if (hero && codeWindow) {
const rate = scrolled * -0.5;
codeWindow.style.transform = `translateY(${rate}px) perspective(1000px) rotateY(-5deg) rotateX(5deg)`;
}
});
// Add loading animation
window.addEventListener('load', () => {
document.body.classList.add('loaded');
});
// Tech items hover effect
document.querySelectorAll('.tech-item').forEach(item => {
item.addEventListener('mouseenter', function() {
this.style.transform = 'translateY(-5px) scale(1.05)';
});
item.addEventListener('mouseleave', function() {
this.style.transform = 'translateY(0) scale(1)';
});
});
// Portfolio items hover effect
document.querySelectorAll('.portfolio-item').forEach(item => {
item.addEventListener('mouseenter', function() {
const img = this.querySelector('.portfolio-image img');
if (img) {
img.style.transform = 'scale(1.1)';
}
});
item.addEventListener('mouseleave', function() {
const img = this.querySelector('.portfolio-image img');
if (img) {
img.style.transform = 'scale(1)';
}
});
});
// Service cards tilt effect
document.querySelectorAll('.service-card').forEach(card => {
card.addEventListener('mousemove', function(e) {
const rect = this.getBoundingClientRect();
const x = e.clientX - rect.left;
const y = e.clientY - rect.top;
const centerX = rect.width / 2;
const centerY = rect.height / 2;
const rotateX = (y - centerY) / 10;
const rotateY = (centerX - x) / 10;
this.style.transform = `perspective(1000px) rotateX(${rotateX}deg) rotateY(${rotateY}deg) translateY(-8px)`;
});
card.addEventListener('mouseleave', function() {
this.style.transform = 'perspective(1000px) rotateX(0) rotateY(0) translateY(0)';
});
});
// Add scroll progress indicator
const scrollProgress = document.createElement('div');
scrollProgress.style.cssText = `
position: fixed;
top: 0;
left: 0;
width: 0%;
height: 3px;
background: linear-gradient(90deg, #3b82f6, #8b5cf6);
z-index: 9999;
transition: width 0.1s ease;
`;
document.body.appendChild(scrollProgress);
window.addEventListener('scroll', () => {
const scrollTop = window.pageYOffset;
const docHeight = document.body.offsetHeight - window.innerHeight;
const scrollPercent = (scrollTop / docHeight) * 100;
scrollProgress.style.width = scrollPercent + '%';
});
// Add cursor trail effect
const cursor = document.createElement('div');
cursor.style.cssText = `
position: fixed;
width: 20px;
height: 20px;
background: radial-gradient(circle, rgba(59, 130, 246, 0.5) 0%, transparent 70%);
border-radius: 50%;
pointer-events: none;
z-index: 9999;
transition: transform 0.1s ease;
`;
document.body.appendChild(cursor);
document.addEventListener('mousemove', (e) => {
cursor.style.left = e.clientX - 10 + 'px';
cursor.style.top = e.clientY - 10 + 'px';
});
// Hide cursor trail on mobile
if (window.innerWidth <= 768) {
cursor.style.display = 'none';
}