forked from komoroshin/H4Usite
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
187 lines (162 loc) · 5.83 KB
/
script.js
File metadata and controls
187 lines (162 loc) · 5.83 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
/* ========================================
Healthy4You - Interactive JavaScript
======================================== */
document.addEventListener('DOMContentLoaded', () => {
// Initialize all components
initNavigation();
initToggles();
initScrollReveal();
initSmoothScroll();
});
/* ----------------------------------------
Navigation
---------------------------------------- */
function initNavigation() {
const nav = document.querySelector('.nav');
const menuBtn = document.getElementById('menuBtn');
const navLinks = document.querySelector('.nav-links');
// Scroll effect for nav
window.addEventListener('scroll', () => {
if (window.scrollY > 50) {
nav.style.background = 'rgba(255, 255, 255, 0.98)';
nav.style.boxShadow = '0 1px 3px rgba(0, 0, 0, 0.1)';
} else {
nav.style.background = 'rgba(255, 255, 255, 0.9)';
nav.style.boxShadow = 'none';
}
});
// Mobile menu toggle
if (menuBtn) {
menuBtn.addEventListener('click', () => {
navLinks.classList.toggle('active');
menuBtn.classList.toggle('active');
});
}
}
/* ----------------------------------------
Toggle Components
---------------------------------------- */
function initToggles() {
// Services Toggle (Patients/Clinics)
const togglePatients = document.getElementById('togglePatients');
const toggleClinics = document.getElementById('toggleClinics');
const patientsContent = document.getElementById('patientsContent');
const clinicsContent = document.getElementById('clinicsContent');
if (togglePatients && toggleClinics) {
togglePatients.addEventListener('click', () => {
togglePatients.classList.add('active');
toggleClinics.classList.remove('active');
patientsContent.classList.add('active');
clinicsContent.classList.remove('active');
});
toggleClinics.addEventListener('click', () => {
toggleClinics.classList.add('active');
togglePatients.classList.remove('active');
clinicsContent.classList.add('active');
patientsContent.classList.remove('active');
});
}
// Testimonials Toggle (Clinicians/Patients)
const toggleClinicians = document.getElementById('toggleClinicians');
const togglePatientsTestimonials = document.getElementById('togglePatientsTestimonials');
const cliniciansContent = document.getElementById('cliniciansContent');
const patientsTestimonialsContent = document.getElementById('patientsTestimonialsContent');
if (toggleClinicians && togglePatientsTestimonials) {
toggleClinicians.addEventListener('click', () => {
toggleClinicians.classList.add('active');
togglePatientsTestimonials.classList.remove('active');
cliniciansContent.classList.add('active');
patientsTestimonialsContent.classList.remove('active');
});
togglePatientsTestimonials.addEventListener('click', () => {
togglePatientsTestimonials.classList.add('active');
toggleClinicians.classList.remove('active');
patientsTestimonialsContent.classList.add('active');
cliniciansContent.classList.remove('active');
});
}
}
/* ----------------------------------------
Scroll Reveal Animation
---------------------------------------- */
function initScrollReveal() {
const revealElements = document.querySelectorAll('.reveal');
const revealOnScroll = () => {
const windowHeight = window.innerHeight;
revealElements.forEach((element, index) => {
const elementTop = element.getBoundingClientRect().top;
const revealPoint = 100;
if (elementTop < windowHeight - revealPoint) {
// Add staggered delay for elements in the same row
setTimeout(() => {
element.classList.add('visible');
}, index * 50);
}
});
};
// Initial check
revealOnScroll();
// Check on scroll
window.addEventListener('scroll', revealOnScroll);
}
/* ----------------------------------------
Smooth Scroll for Anchor Links
---------------------------------------- */
function initSmoothScroll() {
document.querySelectorAll('a[href^="#"]').forEach(anchor => {
anchor.addEventListener('click', function (e) {
const href = this.getAttribute('href');
if (href !== '#') {
e.preventDefault();
const target = document.querySelector(href);
if (target) {
const navHeight = document.querySelector('.nav').offsetHeight;
const targetPosition = target.offsetTop - navHeight;
window.scrollTo({
top: targetPosition,
behavior: 'smooth'
});
}
}
});
});
}
/* ----------------------------------------
Animated Statistics Counter
---------------------------------------- */
function animateStats() {
const stats = document.querySelectorAll('.stat-value[data-target]');
stats.forEach(stat => {
const target = parseInt(stat.getAttribute('data-target'));
const text = stat.textContent;
// Only use prefix if it's + or -
const firstChar = text.charAt(0);
const prefix = (firstChar === '+' || firstChar === '-') ? firstChar : '';
const suffix = text.includes('%') ? '%' : '';
let current = 0;
const increment = target / 50;
const duration = 1500;
const stepTime = duration / 50;
const counter = setInterval(() => {
current += increment;
if (current >= target) {
current = target;
clearInterval(counter);
}
stat.textContent = prefix + Math.floor(current) + suffix;
}, stepTime);
});
}
// Trigger stats animation when trust section is visible
const trustSection = document.getElementById('trust');
if (trustSection) {
const observer = new IntersectionObserver((entries) => {
entries.forEach(entry => {
if (entry.isIntersecting) {
animateStats();
observer.unobserve(entry.target);
}
});
}, { threshold: 0.3 });
observer.observe(trustSection);
}