-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
275 lines (222 loc) · 6.79 KB
/
script.js
File metadata and controls
275 lines (222 loc) · 6.79 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
263
264
265
266
267
268
269
270
271
272
273
274
275
/* ===============================
GLOBAL HELPERS
================================ */
const qs = (el) => document.querySelector(el);
const qsa = (el) => document.querySelectorAll(el);
/* ===============================
SCROLL REVEAL (Animations)
================================ */
const revealElements = qsa(
'.hero, .mission-section, .packages-section, .benefits-section, .calorie-section'
);
const revealOnScroll = () => {
const triggerBottom = window.innerHeight * 0.85;
revealElements.forEach(el => {
const top = el.getBoundingClientRect().top;
if (top < triggerBottom) {
el.classList.add('show');
}
});
};
window.addEventListener('scroll', revealOnScroll);
window.addEventListener('load', revealOnScroll);
/* ===============================
NAVBAR ACTIVE LINK
================================ */
const navLinks = qsa('nav a');
navLinks.forEach(link => {
link.addEventListener('click', () => {
navLinks.forEach(l => l.classList.remove('active'));
link.classList.add('active');
});
});
/* ===============================
HERO BUTTON RIPPLE EFFECT
================================ */
const buttons = qsa('button, .calorie-btn');
buttons.forEach(btn => {
btn.addEventListener('click', function (e) {
const ripple = document.createElement('span');
ripple.classList.add('ripple');
const rect = btn.getBoundingClientRect();
ripple.style.left = `${e.clientX - rect.left}px`;
ripple.style.top = `${e.clientY - rect.top}px`;
btn.appendChild(ripple);
setTimeout(() => ripple.remove(), 600);
});
});
/* ===============================
PACKAGES HOVER & SELECT
================================ */
const packages = qsa('.package-card');
packages.forEach(card => {
card.addEventListener('mouseenter', () => {
packages.forEach(c => c.classList.remove('featured'));
card.classList.add('featured');
});
});
/* ===============================
TESTIMONIALS AUTO FADE (OPTIONAL)
================================ */
const testimonials = qsa('.testimonial-card');
let testimonialIndex = 0;
const rotateTestimonials = () => {
testimonials.forEach(t => t.classList.remove('active'));
testimonials[testimonialIndex].classList.add('active');
testimonialIndex = (testimonialIndex + 1) % testimonials.length;
};
if (testimonials.length > 0) {
setInterval(rotateTestimonials, 4000);
}
/* ===============================
CALORIE BUTTON ACTION
================================ */
const calorieBtn = qs('.calorie-btn');
if (calorieBtn) {
calorieBtn.addEventListener('click', () => {
alert('Calorie Calculator coming soon 🚀');
});
}
/* ===============================
SMOOTH SCROLL
================================ */
qsa('a[href^="#"]').forEach(anchor => {
anchor.addEventListener('click', function (e) {
e.preventDefault();
qs(this.getAttribute('href'))?.scrollIntoView({
behavior: 'smooth'
});
});
});
/* =========================
NAVBAR SCROLL EFFECT
========================= */
const navbar = document.querySelector(".navbar");
window.addEventListener("scroll", () => {
if (window.scrollY > 50) {
navbar.classList.add("scrolled");
}
else
{
navbar.classList.remove("scrolled");
}
});
/* =========================
SMOOTH SCROLL (links)
========================= */
document.querySelectorAll('a[href^="#"]').forEach(link => {
link.addEventListener("click", e => {
e.preventDefault();
const target = document.querySelector(link.getAttribute("href"));
if (target) {
target.scrollIntoView({ behavior: "smooth" });
}
});
});
/* =========================
HERO BUTTONS
========================= */
const subscribeBtn = document.querySelector(".subscribe-btn");
if (subscribeBtn) {
subscribeBtn.addEventListener("click", () => {
alert("Redirect to subscription page 🚀");
});
}
if (calorieBtn) {
calorieBtn.addEventListener("click", () => {
alert("Open calorie calculator 🔥");
});
}
/* =========================
FAQ ACCORDION
========================= */
const faqItems = document.querySelectorAll(".faq-item");
faqItems.forEach(item => {
item.addEventListener("click", () => {
// اقفل الكل
faqItems.forEach(i => {
if (i !== item) i.classList.remove("active");
});
// افتح/اقفل الحالي
item.classList.toggle("active");
});
});
/* =========================
FAQ ANSWERS (اختياري)
========================= */
faqItems.forEach(item => {
const answer = item.querySelector(".faq-answer");
if (answer) answer.style.maxHeight = "0px";
item.addEventListener("click", () => {
if (!answer) return;
if (item.classList.contains("active")) {
answer.style.maxHeight = answer.scrollHeight + "px";
} else {
answer.style.maxHeight = "0px";
}
});
});
/* =========================
LANGUAGE SWITCH (AR / EN)
========================= */
const langBtn = document.querySelector(".lang-btn");
if (langBtn) {
langBtn.addEventListener("click", () => {
document.body.classList.toggle("rtl");
if (document.body.classList.contains("rtl")) {
document.documentElement.setAttribute("dir", "rtl");
langBtn.innerText = "English";
} else {
document.documentElement.setAttribute("dir", "ltr");
langBtn.innerText = "العربية";
}
});
}
/* =========================
SCROLL ANIMATIONS
========================= */
const animatedElements = document.querySelectorAll(
".hero-content, .faq-item, .footer-links, .footer-brand"
);
const observer = new IntersectionObserver(entries => {
entries.forEach(entry => {
if (entry.isIntersecting) {
entry.target.classList.add("show");
}
});
}, { threshold: 0.15 });
animatedElements.forEach(el => observer.observe(el));
/* =========================
TESTIMONIALS SLIDER
========================= */
const track = document.querySelector('.slider-track');
const slides = document.querySelectorAll('.slide');
const next = document.querySelector('.right');
const prev = document.querySelector('.left');
let index = 0;
const visibleSlides = 3;
const slideWidth = 330;
function moveSlide() {
track.style.transform = `translateX(-${index * slideWidth}px)`;
}
next.onclick = () => {
if (index < slides.length - visibleSlides) {
index++;
moveSlide();
}
};
prev.onclick = () => {
if (index > 0) {
index--;
moveSlide();
}
};
// Auto Slide
setInterval(() => {
if (index >= slides.length - visibleSlides) {
index = 0;
} else {
index++;
}
moveSlide();
}, 4000);