-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
232 lines (201 loc) · 7.21 KB
/
script.js
File metadata and controls
232 lines (201 loc) · 7.21 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
/* ============================================
ESSENTIQUE — Interactions & Animations
Apple-level micro-interactions
============================================ */
document.addEventListener('DOMContentLoaded', () => {
// ---- Preloader ----
window.addEventListener('load', () => {
setTimeout(() => {
document.getElementById('preloader').classList.add('loaded');
initHeroAnimations();
}, 1800);
});
// Fallback: remove preloader after 3s regardless
setTimeout(() => {
document.getElementById('preloader').classList.add('loaded');
initHeroAnimations();
}, 3000);
// ---- Hero animations ----
let heroInitialized = false;
function initHeroAnimations() {
if (heroInitialized) return;
heroInitialized = true;
// Slow zoom on hero image
const heroImg = document.querySelector('.hero-img');
if (heroImg) {
setTimeout(() => heroImg.classList.add('loaded'), 100);
}
// Typing animation
const tagline = 'Luxurious Essential Oils \u00B7 Handcrafted Naturally';
const typedEl = document.querySelector('.tagline-typed');
if (typedEl) {
let i = 0;
const typeInterval = setInterval(() => {
if (i < tagline.length) {
typedEl.textContent += tagline[i];
i++;
} else {
clearInterval(typeInterval);
setTimeout(() => typedEl.classList.add('done'), 2000);
}
}, 45);
}
// Stagger hero reveals
const heroReveals = document.querySelectorAll('#hero .reveal');
heroReveals.forEach((el, i) => {
setTimeout(() => {
el.classList.add('visible');
}, 300 + i * 200);
});
}
// ---- Navbar scroll ----
const navbar = document.getElementById('navbar');
function handleNavScroll() {
const scrollY = window.scrollY;
if (scrollY > 80) {
navbar.classList.add('scrolled');
} else {
navbar.classList.remove('scrolled');
}
}
window.addEventListener('scroll', handleNavScroll, { passive: true });
// ---- Mobile menu ----
const toggle = document.querySelector('.nav-toggle');
const mobileMenu = document.getElementById('mobile-menu');
if (toggle && mobileMenu) {
toggle.addEventListener('click', () => {
toggle.classList.toggle('active');
mobileMenu.classList.toggle('open');
document.body.style.overflow = mobileMenu.classList.contains('open') ? 'hidden' : '';
});
mobileMenu.querySelectorAll('a').forEach(link => {
link.addEventListener('click', () => {
toggle.classList.remove('active');
mobileMenu.classList.remove('open');
document.body.style.overflow = '';
});
});
}
// ---- Smooth anchor scrolling ----
document.querySelectorAll('a[href^="#"]').forEach(anchor => {
anchor.addEventListener('click', (e) => {
e.preventDefault();
const target = document.querySelector(anchor.getAttribute('href'));
if (target) {
const offset = 80;
const top = target.getBoundingClientRect().top + window.scrollY - offset;
window.scrollTo({ top, behavior: 'smooth' });
}
});
});
// ---- Intersection Observer — Reveal on scroll ----
const observerOptions = {
root: null,
rootMargin: '0px 0px -60px 0px',
threshold: 0.1
};
const revealObserver = new IntersectionObserver((entries) => {
entries.forEach(entry => {
if (entry.isIntersecting) {
const delay = entry.target.style.animationDelay;
if (delay) {
const ms = parseFloat(delay) * 1000;
setTimeout(() => entry.target.classList.add('visible'), ms);
} else {
entry.target.classList.add('visible');
}
revealObserver.unobserve(entry.target);
}
});
}, observerOptions);
// Observe all reveal elements except hero (hero is handled separately)
document.querySelectorAll('.reveal:not(#hero .reveal), .reveal-slide-right, .reveal-scale').forEach(el => {
revealObserver.observe(el);
});
// ---- Parallax on hero ----
let ticking = false;
function updateParallax() {
const scrollY = window.scrollY;
const heroImg = document.querySelector('.hero-img');
if (heroImg && scrollY < window.innerHeight) {
heroImg.style.transform = 'scale(' + (1 + scrollY * 0.0001) + ') translateY(' + (scrollY * 0.3) + 'px)';
}
ticking = false;
}
window.addEventListener('scroll', () => {
if (!ticking) {
requestAnimationFrame(updateParallax);
ticking = true;
}
}, { passive: true });
// ---- Gallery infinite scroll (clone items via DOM methods) ----
const galleryTrack = document.querySelector('.gallery-track');
if (galleryTrack) {
const items = Array.from(galleryTrack.children);
items.forEach(item => {
const clone = item.cloneNode(true);
galleryTrack.appendChild(clone);
});
}
// ---- Gold line draw animation on scroll ----
const goldLines = document.querySelectorAll('.gold-line, .gold-line-sm');
const lineObserver = new IntersectionObserver((entries) => {
entries.forEach(entry => {
if (entry.isIntersecting) {
entry.target.style.animation = 'drawLine 1s var(--ease-out) forwards';
lineObserver.unobserve(entry.target);
}
});
}, { threshold: 0.5 });
goldLines.forEach(line => {
line.style.transform = 'scaleX(0)';
lineObserver.observe(line);
});
// Add the drawLine keyframe dynamically
const styleSheet = document.createElement('style');
styleSheet.textContent = '@keyframes drawLine { from { transform: scaleX(0); } to { transform: scaleX(1); } }';
document.head.appendChild(styleSheet);
// ---- Smooth hover tilt on product cards ----
document.querySelectorAll('.product-card').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 tiltX = (y - centerY) / centerY * 2;
const tiltY = (centerX - x) / centerX * 2;
card.style.transform = 'translateY(-4px) perspective(800px) rotateX(' + tiltX + 'deg) rotateY(' + tiltY + 'deg)';
});
card.addEventListener('mouseleave', () => {
card.style.transform = 'translateY(0) perspective(800px) rotateX(0) rotateY(0)';
});
});
// ---- Ambient cursor glow ----
const cursor = document.createElement('div');
cursor.id = 'cursor-glow';
cursor.style.position = 'fixed';
cursor.style.width = '200px';
cursor.style.height = '200px';
cursor.style.borderRadius = '50%';
cursor.style.background = 'radial-gradient(circle, rgba(201,169,110,0.06) 0%, transparent 70%)';
cursor.style.pointerEvents = 'none';
cursor.style.zIndex = '9998';
cursor.style.transform = 'translate(-50%, -50%)';
cursor.style.transition = 'opacity 0.3s';
cursor.style.opacity = '0';
document.body.appendChild(cursor);
let cursorVisible = false;
document.addEventListener('mousemove', (e) => {
cursor.style.left = e.clientX + 'px';
cursor.style.top = e.clientY + 'px';
if (!cursorVisible) {
cursorVisible = true;
cursor.style.opacity = '1';
}
});
document.addEventListener('mouseleave', () => {
cursorVisible = false;
cursor.style.opacity = '0';
});
});