-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsize-guide-script.js
More file actions
485 lines (417 loc) · 15.1 KB
/
Copy pathsize-guide-script.js
File metadata and controls
485 lines (417 loc) · 15.1 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
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
// Size Guide Page JavaScript
document.addEventListener('DOMContentLoaded', function() {
// Initialize hamburger menu
initHamburgerMenu();
// Initialize smooth scrolling
initSmoothScrolling();
// Initialize size card animations
initSizeCardAnimations();
// Initialize usage card animations
initUsageCardAnimations();
// Initialize calculator functionality
initCalculator();
// Initialize table hover effects
initTableEffects();
});
// Hamburger Menu Functionality
function initHamburgerMenu() {
const hamburger = document.querySelector('.hamburger');
const navMenu = document.querySelector('.nav-menu');
if (hamburger && navMenu) {
hamburger.addEventListener('click', function() {
hamburger.classList.toggle('active');
navMenu.classList.toggle('active');
});
// Close menu when clicking on a link
document.querySelectorAll('.nav-link').forEach(link => {
link.addEventListener('click', () => {
hamburger.classList.remove('active');
navMenu.classList.remove('active');
});
});
}
}
// Smooth Scrolling
function initSmoothScrolling() {
document.querySelectorAll('a[href^="#"]').forEach(anchor => {
anchor.addEventListener('click', function (e) {
e.preventDefault();
const target = document.querySelector(this.getAttribute('href'));
if (target) {
target.scrollIntoView({
behavior: 'smooth',
block: 'start'
});
}
});
});
}
// Size Card Animations
function initSizeCardAnimations() {
const sizeCards = document.querySelectorAll('.size-card');
// Intersection Observer for fade-in animations
const observer = new IntersectionObserver((entries) => {
entries.forEach(entry => {
if (entry.isIntersecting) {
entry.target.style.opacity = '1';
entry.target.style.transform = 'translateY(0)';
}
});
}, {
threshold: 0.1,
rootMargin: '0px 0px -50px 0px'
});
sizeCards.forEach((card, index) => {
card.style.opacity = '0';
card.style.transform = 'translateY(30px)';
card.style.transition = `opacity 0.6s ease ${index * 0.1}s, transform 0.6s ease ${index * 0.1}s`;
observer.observe(card);
});
}
// Usage Card Animations
function initUsageCardAnimations() {
const usageCards = document.querySelectorAll('.usage-card');
const observer = new IntersectionObserver((entries) => {
entries.forEach(entry => {
if (entry.isIntersecting) {
entry.target.style.opacity = '1';
entry.target.style.transform = 'translateY(0)';
}
});
}, {
threshold: 0.1,
rootMargin: '0px 0px -50px 0px'
});
usageCards.forEach((card, index) => {
card.style.opacity = '0';
card.style.transform = 'translateY(30px)';
card.style.transition = `opacity 0.6s ease ${index * 0.1}s, transform 0.6s ease ${index * 0.1}s`;
observer.observe(card);
});
}
// Calculator Functionality
function initCalculator() {
const calculateBtn = document.getElementById('calculate-btn');
const calculatorResult = document.getElementById('calculator-result');
if (calculateBtn && calculatorResult) {
calculateBtn.addEventListener('click', function() {
const frequency = document.getElementById('usage-frequency').value;
const sprays = document.getElementById('sprays-per-use').value;
const duration = document.getElementById('duration').value;
if (!frequency || !sprays || !duration) {
showCalculatorError('Please fill in all fields to get a recommendation.');
return;
}
// Show loading state
calculateBtn.innerHTML = '<i class="fas fa-spinner fa-spin"></i> Calculating...';
calculateBtn.disabled = true;
// Simulate calculation delay
setTimeout(() => {
const recommendation = calculateSizeRecommendation(frequency, sprays, duration);
showCalculatorResult(recommendation);
calculateBtn.innerHTML = '<i class="fas fa-calculator"></i> Calculate Recommended Size';
calculateBtn.disabled = false;
}, 1500);
});
}
}
// Calculate Size Recommendation
function calculateSizeRecommendation(frequency, sprays, duration) {
// Define usage patterns
const usagePatterns = {
daily: 365,
weekly: 156, // 3 times per week
occasional: 52, // once per week
rarely: 12 // once per month
};
// Define spray amounts (ml per spray)
const sprayAmounts = {
'1': 0.1,
'2': 0.2,
'3': 0.3,
'4': 0.4
};
// Calculate total usage per year
const usesPerYear = usagePatterns[frequency];
const mlPerUse = sprayAmounts[sprays];
const totalMlPerYear = usesPerYear * mlPerUse;
// Calculate required ml based on duration
const durationMultipliers = {
'3months': 0.25,
'6months': 0.5,
'1year': 1,
'2years': 2
};
const requiredMl = totalMlPerYear * durationMultipliers[duration];
// Determine size recommendation
let recommendation = {
size: '',
ml: 0,
applications: 0,
reasoning: ''
};
if (requiredMl <= 5) {
recommendation = {
size: 'Sample Size (1-5 ml)',
ml: 5,
applications: Math.round(5 / mlPerUse),
reasoning: 'Perfect for testing new fragrances before committing to a larger size.'
};
} else if (requiredMl <= 15) {
recommendation = {
size: 'Mini Size (10-15 ml)',
ml: 15,
applications: Math.round(15 / mlPerUse),
reasoning: 'Ideal for travel and occasional use. Great value for your usage pattern.'
};
} else if (requiredMl <= 100) {
recommendation = {
size: 'Standard Size (50-100 ml)',
ml: 100,
applications: Math.round(100 / mlPerUse),
reasoning: 'The most popular choice. Perfect balance of value and longevity.'
};
} else {
recommendation = {
size: 'Large Size (125-200 ml)',
ml: 200,
applications: Math.round(200 / mlPerUse),
reasoning: 'For fragrance enthusiasts who want extended use of their favorite scents.'
};
}
return {
...recommendation,
frequency: frequency,
sprays: sprays,
duration: duration,
calculatedMl: Math.round(requiredMl)
};
}
// Show Calculator Result
function showCalculatorResult(data) {
const calculatorResult = document.getElementById('calculator-result');
const resultHTML = `
<div class="calculator-result-content">
<div class="result-header">
<i class="fas fa-check-circle"></i>
<h3>Your Perfect Size</h3>
</div>
<div class="result-details">
<div class="result-size">
<h4>${data.size}</h4>
<p class="size-amount">${data.ml} ml</p>
</div>
<div class="result-stats">
<div class="stat">
<span class="stat-label">Applications:</span>
<span class="stat-value">${data.applications}</span>
</div>
<div class="stat">
<span class="stat-label">Your Usage:</span>
<span class="stat-value">${data.frequency} (${data.sprays} sprays)</span>
</div>
<div class="stat">
<span class="stat-label">Duration:</span>
<span class="stat-value">${data.duration}</span>
</div>
</div>
<div class="result-reasoning">
<p>${data.reasoning}</p>
</div>
</div>
</div>
`;
calculatorResult.innerHTML = resultHTML;
// Add result styles
addCalculatorResultStyles();
}
// Show Calculator Error
function showCalculatorError(message) {
const calculatorResult = document.getElementById('calculator-result');
calculatorResult.innerHTML = `
<div class="calculator-error">
<i class="fas fa-exclamation-triangle"></i>
<p>${message}</p>
</div>
`;
}
// Table Effects
function initTableEffects() {
const tableRows = document.querySelectorAll('.conversion-table tbody tr');
tableRows.forEach((row, index) => {
row.style.opacity = '0';
row.style.transform = 'translateX(-20px)';
row.style.transition = `opacity 0.6s ease ${index * 0.1}s, transform 0.6s ease ${index * 0.1}s`;
// Trigger animation when table comes into view
const observer = new IntersectionObserver((entries) => {
entries.forEach(entry => {
if (entry.isIntersecting) {
entry.target.style.opacity = '1';
entry.target.style.transform = 'translateX(0)';
}
});
}, { threshold: 0.1 });
observer.observe(row);
});
}
// Dynamic navbar background on scroll
window.addEventListener('scroll', function() {
const navbar = document.querySelector('.navbar');
if (navbar) {
if (window.scrollY > 50) {
navbar.style.background = 'rgba(18, 18, 18, 0.95)';
navbar.style.backdropFilter = 'blur(10px)';
} else {
navbar.style.background = 'rgba(18, 18, 18, 0.8)';
navbar.style.backdropFilter = 'blur(5px)';
}
}
});
// Search functionality
document.addEventListener('DOMContentLoaded', function() {
const searchInput = document.querySelector('.search-input');
const searchBtn = document.querySelector('.search-btn');
if (searchInput && searchBtn) {
searchBtn.addEventListener('click', function() {
const query = searchInput.value.trim();
if (query) {
window.location.href = `main.html?search=${encodeURIComponent(query)}`;
}
});
searchInput.addEventListener('keypress', function(e) {
if (e.key === 'Enter') {
const query = this.value.trim();
if (query) {
window.location.href = `main.html?search=${encodeURIComponent(query)}`;
}
}
});
}
});
// Add calculator result styles
function addCalculatorResultStyles() {
if (!document.getElementById('calculator-result-styles')) {
const style = document.createElement('style');
style.id = 'calculator-result-styles';
style.textContent = `
.calculator-result-content {
color: var(--warm-white);
text-align: center;
}
.result-header {
margin-bottom: 2rem;
}
.result-header i {
font-size: 3rem;
color: #4CAF50;
margin-bottom: 1rem;
display: block;
}
.result-header h3 {
font-family: 'Playfair Display', serif;
font-size: 1.8rem;
color: var(--warm-white);
margin-bottom: 0;
}
.result-size {
margin-bottom: 2rem;
padding: 1.5rem;
background: rgba(18, 18, 18, 0.3);
border: 2px solid var(--antique-gold);
border-radius: 10px;
}
.result-size h4 {
font-family: 'Playfair Display', serif;
font-size: 1.3rem;
color: var(--antique-gold);
margin-bottom: 0.5rem;
}
.size-amount {
font-size: 1.5rem;
color: var(--warm-white);
font-weight: 600;
}
.result-stats {
margin-bottom: 2rem;
}
.stat {
display: flex;
justify-content: space-between;
margin-bottom: 0.75rem;
padding: 0.5rem 0;
border-bottom: 1px solid rgba(201, 166, 70, 0.2);
}
.stat:last-child {
border-bottom: none;
}
.stat-label {
color: rgba(245, 240, 230, 0.8);
font-weight: 500;
}
.stat-value {
color: var(--antique-gold);
font-weight: 600;
}
.result-reasoning {
background: rgba(18, 18, 18, 0.3);
border: 1px solid rgba(201, 166, 70, 0.3);
border-radius: 10px;
padding: 1rem;
}
.result-reasoning p {
color: rgba(245, 240, 230, 0.9);
line-height: 1.6;
margin: 0;
}
.calculator-error {
text-align: center;
color: #ff6b6b;
}
.calculator-error i {
font-size: 3rem;
margin-bottom: 1rem;
display: block;
}
.calculator-error p {
font-size: 1rem;
}
`;
document.head.appendChild(style);
}
}
// Page load animation
window.addEventListener('load', function() {
document.body.style.opacity = '0';
document.body.style.transition = 'opacity 0.5s ease';
setTimeout(() => {
document.body.style.opacity = '1';
}, 100);
});
// Size card hover effects
document.addEventListener('DOMContentLoaded', function() {
const sizeCards = document.querySelectorAll('.size-card');
sizeCards.forEach(card => {
card.addEventListener('mouseenter', function() {
this.style.transform = 'translateY(-5px) scale(1.02)';
});
card.addEventListener('mouseleave', function() {
if (this.classList.contains('featured')) {
this.style.transform = 'scale(1.05)';
} else {
this.style.transform = 'translateY(0) scale(1)';
}
});
});
});
// Usage card hover effects
document.addEventListener('DOMContentLoaded', function() {
const usageCards = document.querySelectorAll('.usage-card');
usageCards.forEach(card => {
card.addEventListener('mouseenter', function() {
this.style.transform = 'translateY(-5px) scale(1.02)';
});
card.addEventListener('mouseleave', function() {
this.style.transform = 'translateY(0) scale(1)';
});
});
});