-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
83 lines (71 loc) · 3.16 KB
/
script.js
File metadata and controls
83 lines (71 loc) · 3.16 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
document.addEventListener('DOMContentLoaded', () => {
const reduceMotion = window.matchMedia('(prefers-reduced-motion: reduce)').matches;
// 1. Анимация счетчиков
const countTargets = document.querySelectorAll('.count-up');
const numberFormatter = new Intl.NumberFormat('ru-RU');
const setCounterValue = (el, value) => {
const prefix = el.dataset.prefix || '';
const suffix = el.dataset.suffix || '';
el.textContent = `${prefix}${numberFormatter.format(value)}${suffix}`;
};
const animateValue = (el, start, end, duration) => {
let startTimestamp = null;
const step = (timestamp) => {
if (!startTimestamp) startTimestamp = timestamp;
const progress = Math.min((timestamp - startTimestamp) / duration, 1);
const value = Math.floor(progress * (end - start) + start);
setCounterValue(el, value);
if (progress < 1) {
window.requestAnimationFrame(step);
}
};
window.requestAnimationFrame(step);
};
if (countTargets.length) {
if (reduceMotion) {
countTargets.forEach((el) => {
const endValue = parseInt(el.dataset.count, 10);
if (!Number.isNaN(endValue)) {
setCounterValue(el, endValue);
}
});
} else {
const observer = new IntersectionObserver((entries) => {
entries.forEach(entry => {
if (entry.isIntersecting) {
const target = entry.target;
const endValue = parseInt(target.getAttribute('data-count'), 10);
if (!Number.isNaN(endValue)) {
animateValue(target, 0, endValue, 2000);
}
observer.unobserve(target);
}
});
}, { threshold: 0.5 });
countTargets.forEach(counter => {
observer.observe(counter);
});
}
}
// 2. Параллакс эффект для карточек при движении мыши
if (!reduceMotion) {
const cards = document.querySelectorAll('.artist-card');
cards.forEach(card => {
card.addEventListener('mousemove', (e) => {
const rect = card.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) / centerY) * -5; // максимум 5 градусов
const rotateY = ((x - centerX) / centerX) * 5;
card.style.transform = `perspective(1000px) rotateX(${rotateX}deg) rotateY(${rotateY}deg) scale(1.02)`;
});
card.addEventListener('mouseleave', () => {
card.style.transform = 'perspective(1000px) rotateX(0) rotateY(0) scale(1)';
});
});
}
});