-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
199 lines (174 loc) · 6.03 KB
/
script.js
File metadata and controls
199 lines (174 loc) · 6.03 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
/* ============================================
OLD SCHOOL FITNESS CLUB — Interactions
============================================ */
document.addEventListener('DOMContentLoaded', () => {
initScrollAnimations();
initNavbar();
initMobileMenu();
initParticles();
initSmoothScroll();
initAnalyticsEvents();
});
/* --- Scroll Reveal Animations --- */
function initScrollAnimations() {
const observer = new IntersectionObserver(
(entries) => {
entries.forEach((entry) => {
if (entry.isIntersecting) {
entry.target.classList.add('visible');
// Don't unobserve, so they reanimate if scrolled back
}
});
},
{
threshold: 0.1,
rootMargin: '0px 0px -60px 0px',
}
);
document.querySelectorAll('.animate-in').forEach((el) => {
observer.observe(el);
});
}
/* --- Navbar Scroll Effect --- */
function initNavbar() {
const navbar = document.getElementById('navbar');
let ticking = false;
window.addEventListener('scroll', () => {
if (!ticking) {
requestAnimationFrame(() => {
if (window.scrollY > 80) {
navbar.classList.add('scrolled');
} else {
navbar.classList.remove('scrolled');
}
ticking = false;
});
ticking = true;
}
});
}
/* --- Mobile Menu --- */
function initMobileMenu() {
const toggle = document.getElementById('navToggle');
const links = document.getElementById('navLinks');
if (!toggle || !links) return;
toggle.addEventListener('click', () => {
toggle.classList.toggle('active');
links.classList.toggle('open');
document.body.style.overflow = links.classList.contains('open') ? 'hidden' : '';
});
// Close on link click
links.querySelectorAll('a').forEach((link) => {
link.addEventListener('click', () => {
toggle.classList.remove('active');
links.classList.remove('open');
document.body.style.overflow = '';
});
});
}
/* --- Floating Particles --- */
function initParticles() {
const container = document.getElementById('particles');
if (!container) return;
const particleCount = 30;
for (let i = 0; i < particleCount; i++) {
const particle = document.createElement('div');
particle.classList.add('particle');
const x = Math.random() * 100;
const delay = Math.random() * 8;
const duration = 6 + Math.random() * 6;
const size = 2 + Math.random() * 3;
particle.style.left = `${x}%`;
particle.style.width = `${size}px`;
particle.style.height = `${size}px`;
particle.style.animationDelay = `${delay}s`;
particle.style.animationDuration = `${duration}s`;
container.appendChild(particle);
}
}
/* --- Smooth Scroll for Nav Links --- */
function initSmoothScroll() {
document.querySelectorAll('a[href^="#"]').forEach((anchor) => {
anchor.addEventListener('click', function (e) {
e.preventDefault();
const target = document.querySelector(this.getAttribute('href'));
if (target) {
const offset = 80; // navbar height
const top = target.getBoundingClientRect().top + window.pageYOffset - offset;
window.scrollTo({
top: top,
behavior: 'smooth',
});
}
});
});
}
/* --- Google Analytics Events --- */
function initAnalyticsEvents() {
if (typeof gtag !== 'function') return;
// WhatsApp CTA button clicks
document.querySelectorAll('a[href*="chat.whatsapp.com"]').forEach((btn) => {
btn.addEventListener('click', () => {
gtag('event', 'whatsapp_click', {
event_category: 'CTA',
event_label: btn.closest('.join') ? 'Join Section' : 'Other',
});
});
});
// Google Maps location link
document.querySelectorAll('a[href*="maps.app.goo.gl"]').forEach((link) => {
link.addEventListener('click', () => {
gtag('event', 'map_click', {
event_category: 'CTA',
event_label: 'Location Link',
});
});
});
// Hero "Вступить в клуб" button
const heroCta = document.querySelector('.hero .btn-primary');
if (heroCta) {
heroCta.addEventListener('click', () => {
gtag('event', 'hero_cta_click', {
event_category: 'CTA',
event_label: 'Hero Join Button',
});
});
}
// Hero "Узнать больше" button
const heroLearnMore = document.querySelector('.hero .btn-outline');
if (heroLearnMore) {
heroLearnMore.addEventListener('click', () => {
gtag('event', 'learn_more_click', {
event_category: 'Navigation',
event_label: 'Hero Learn More',
});
});
}
// Nav "Вступить" button
const navCta = document.querySelector('.nav-cta');
if (navCta) {
navCta.addEventListener('click', () => {
gtag('event', 'nav_cta_click', {
event_category: 'CTA',
event_label: 'Nav Join Button',
});
});
}
// Track section views
const sections = document.querySelectorAll('.section, .hero');
const sectionObserver = new IntersectionObserver(
(entries) => {
entries.forEach((entry) => {
if (entry.isIntersecting) {
gtag('event', 'section_view', {
event_category: 'Engagement',
event_label: entry.target.id || 'unknown',
});
sectionObserver.unobserve(entry.target);
}
});
},
{ threshold: 0.3 }
);
sections.forEach((section) => sectionObserver.observe(section));
}