-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
171 lines (151 loc) · 4.95 KB
/
Copy pathscript.js
File metadata and controls
171 lines (151 loc) · 4.95 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
function toggleTheme() {
document.body.classList.toggle('dark-theme');
const button = document.querySelector('.theme-toggle');
button.textContent = document.body.classList.contains('dark-theme') ? '☀️' : '🌙';
}
function toggleMenu() {
const menu = document.querySelector('.nav-menu');
menu.classList.toggle('active');
}
document.querySelectorAll('.nav-menu a').forEach(anchor => {
anchor.addEventListener('click', function(e) {
e.preventDefault();
const section = document.querySelector(this.getAttribute('href'));
section.scrollIntoView({ behavior: 'smooth' });
toggleMenu();
});
});
function handleScroll() {
const sections = document.querySelectorAll('section');
const triggerPoint = window.innerHeight * 0.8;
sections.forEach(section => {
const sectionTop = section.getBoundingClientRect().top;
if (sectionTop < triggerPoint) {
section.classList.add('visible');
}
});
}
window.addEventListener('scroll', handleScroll);
window.addEventListener('load', handleScroll);
// Typewriter effect
function typeWriter(element, text, speed) {
let i = 0;
element.textContent = '';
function type() {
if (i < text.length) {
element.textContent += text.charAt(i);
i++;
setTimeout(type, speed);
}
}
type();
}
window.addEventListener('load', () => {
typeWriter(document.getElementById('name'), 'Андрей Голиков', 100);
setTimeout(() => typeWriter(document.getElementById('title'), 'Backend & DevOps Специалист', 100), 1500);
});
// Stats counter
function animateStats() {
const counters = document.querySelectorAll('.stat-number');
counters.forEach(counter => {
const target = +counter.getAttribute('data-target');
let count = 0;
const speed = 50;
const updateCount = () => {
const increment = target / speed;
if (count < target) {
count += increment;
counter.textContent = Math.ceil(count);
setTimeout(updateCount, 20);
} else {
counter.textContent = target;
}
};
updateCount();
});
}
const statsSection = document.getElementById('stats');
const observer = new IntersectionObserver((entries) => {
if (entries[0].isIntersecting) {
animateStats();
observer.unobserve(statsSection);
}
}, { threshold: 0.5 });
observer.observe(statsSection);
// Carousel
const carouselInner = document.querySelector('.carousel-inner');
const carouselItems = document.querySelectorAll('.project-item');
const prevBtn = document.querySelector('.carousel-prev');
const nextBtn = document.querySelector('.carousel-next');
let currentIndex = 0;
function updateCarousel() {
carouselItems.forEach((item, index) => {
item.classList.toggle('active', index === currentIndex);
});
}
prevBtn.addEventListener('click', () => {
currentIndex = (currentIndex > 0) ? currentIndex - 1 : carouselItems.length - 1;
updateCarousel();
});
nextBtn.addEventListener('click', () => {
currentIndex = (currentIndex < carouselItems.length - 1) ? currentIndex + 1 : 0;
updateCarousel();
});
// Particles
const canvas = document.getElementById('particles');
const ctx = canvas.getContext('2d');
canvas.width = window.innerWidth;
canvas.height = window.innerHeight;
let particlesArray = [];
const numberOfParticles = 50;
class Particle {
constructor() {
this.x = Math.random() * canvas.width;
this.y = Math.random() * canvas.height;
this.size = Math.random() * 5 + 1;
this.speedX = Math.random() * 3 - 1.5;
this.speedY = Math.random() * 3 - 1.5;
}
update() {
this.x += this.speedX;
this.y += this.speedY;
if (this.size > 0.2) this.size -= 0.1;
}
draw() {
ctx.fillStyle = 'rgba(0, 180, 216, 0.8)';
ctx.beginPath();
ctx.arc(this.x, this.y, this.size, 0, Math.PI * 2);
ctx.fill();
}
}
function initParticles() {
for (let i = 0; i < numberOfParticles; i++) {
particlesArray.push(new Particle());
}
}
function animateParticles() {
ctx.clearRect(0, 0, canvas.width, canvas.height);
for (let i = 0; i < particlesArray.length; i++) {
particlesArray[i].update();
particlesArray[i].draw();
if (particlesArray[i].size <= 0.2) {
particlesArray.splice(i, 1);
i--;
particlesArray.push(new Particle());
}
}
requestAnimationFrame(animateParticles);
}
canvas.addEventListener('mousemove', (e) => {
for (let i = 0; i < 5; i++) {
particlesArray.push(new Particle());
particlesArray[particlesArray.length - 1].x = e.x;
particlesArray[particlesArray.length - 1].y = e.y;
}
});
window.addEventListener('resize', () => {
canvas.width = window.innerWidth;
canvas.height = window.innerHeight;
});
initParticles();
animateParticles();