-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
319 lines (271 loc) · 10.1 KB
/
script.js
File metadata and controls
319 lines (271 loc) · 10.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
// Mobile Navigation Toggle
const mobileToggle = document.getElementById('mobileToggle');
const navMenu = document.getElementById('navMenu');
if (mobileToggle) {
mobileToggle.addEventListener('click', () => {
navMenu.classList.toggle('active');
mobileToggle.classList.toggle('active');
// Animate hamburger menu
const spans = mobileToggle.querySelectorAll('span');
if (navMenu.classList.contains('active')) {
spans[0].style.transform = 'rotate(45deg) translate(5px, 5px)';
spans[1].style.opacity = '0';
spans[2].style.transform = 'rotate(-45deg) translate(7px, -6px)';
} else {
spans[0].style.transform = 'none';
spans[1].style.opacity = '1';
spans[2].style.transform = 'none';
}
});
}
// Close mobile menu when clicking outside
document.addEventListener('click', (e) => {
if (navMenu && mobileToggle) {
if (!navMenu.contains(e.target) && !mobileToggle.contains(e.target)) {
navMenu.classList.remove('active');
mobileToggle.classList.remove('active');
const spans = mobileToggle.querySelectorAll('span');
spans[0].style.transform = 'none';
spans[1].style.opacity = '1';
spans[2].style.transform = 'none';
}
}
});
// Close mobile menu when clicking on a link
if (navMenu) {
const navLinks = navMenu.querySelectorAll('a');
navLinks.forEach(link => {
link.addEventListener('click', () => {
navMenu.classList.remove('active');
if (mobileToggle) {
mobileToggle.classList.remove('active');
const spans = mobileToggle.querySelectorAll('span');
spans[0].style.transform = 'none';
spans[1].style.opacity = '1';
spans[2].style.transform = 'none';
}
});
});
}
// Navbar scroll effect
const navbar = document.getElementById('navbar');
let lastScroll = 0;
window.addEventListener('scroll', () => {
const currentScroll = window.pageYOffset;
if (currentScroll > 50) {
navbar.classList.add('scrolled');
} else {
navbar.classList.remove('scrolled');
}
lastScroll = currentScroll;
});
// Smooth scroll for anchor links
document.querySelectorAll('a[href^="#"]').forEach(anchor => {
anchor.addEventListener('click', function (e) {
const href = this.getAttribute('href');
if (href !== '#' && href !== '') {
e.preventDefault();
const target = document.querySelector(href);
if (target) {
target.scrollIntoView({
behavior: 'smooth',
block: 'start'
});
}
}
});
});
// Copy to clipboard functionality for code blocks
const copyButtons = document.querySelectorAll('.copy-btn');
copyButtons.forEach(button => {
button.addEventListener('click', async () => {
const textToCopy = button.getAttribute('data-copy');
try {
await navigator.clipboard.writeText(textToCopy);
// Visual feedback
const originalHTML = button.innerHTML;
button.innerHTML = `
<svg width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2">
<polyline points="20 6 9 17 4 12"></polyline>
</svg>
`;
button.style.background = 'rgba(39, 201, 63, 0.2)';
setTimeout(() => {
button.innerHTML = originalHTML;
button.style.background = '';
}, 2000);
} catch (err) {
console.error('Failed to copy:', err);
alert('Failed to copy to clipboard');
}
});
});
// Intersection Observer for fade-in animations
const observerOptions = {
threshold: 0.1,
rootMargin: '0px 0px -50px 0px'
};
const observer = new IntersectionObserver((entries) => {
entries.forEach(entry => {
if (entry.isIntersecting) {
entry.target.style.opacity = '1';
entry.target.style.transform = 'translateY(0)';
}
});
}, observerOptions);
// Animate elements on scroll
const animateOnScroll = document.querySelectorAll('.feature-card, .content-block, .step-card, .value-item, .info-card, .resource-card, .install-card');
animateOnScroll.forEach(el => {
el.style.opacity = '0';
el.style.transform = 'translateY(30px)';
el.style.transition = 'opacity 0.6s ease, transform 0.6s ease';
observer.observe(el);
});
// Parallax effect for hero section
const heroSection = document.querySelector('.hero');
if (heroSection) {
window.addEventListener('scroll', () => {
const scrolled = window.pageYOffset;
const parallaxSpeed = 0.5;
if (scrolled < window.innerHeight) {
heroSection.style.transform = `translateY(${scrolled * parallaxSpeed}px)`;
}
});
}
// Add active class to current page in navigation
const currentLocation = window.location.pathname;
const navLinks = document.querySelectorAll('.nav-menu a');
navLinks.forEach(link => {
const linkPath = new URL(link.href).pathname;
if (currentLocation === linkPath ||
(currentLocation === '/' && linkPath.includes('index.html')) ||
(currentLocation.includes(linkPath) && linkPath !== '/')) {
link.classList.add('active');
}
});
// Animated counter for stats
const stats = document.querySelectorAll('.stat-number');
const animateCounter = (element, target, duration) => {
const targetNumber = parseFloat(target.replace(/[^0-9.]/g, ''));
if (isNaN(targetNumber)) return;
const increment = targetNumber / (duration / 16);
let current = 0;
const updateCounter = () => {
current += increment;
if (current < targetNumber) {
element.textContent = Math.floor(current).toLocaleString() + (target.includes('+') ? '+' : '');
requestAnimationFrame(updateCounter);
} else {
element.textContent = target;
}
};
updateCounter();
};
const statsObserver = new IntersectionObserver((entries) => {
entries.forEach(entry => {
if (entry.isIntersecting && !entry.target.dataset.animated) {
const target = entry.target.textContent;
entry.target.dataset.animated = 'true';
if (target.match(/\d+/)) {
animateCounter(entry.target, target, 2000);
}
}
});
}, { threshold: 0.5 });
stats.forEach(stat => {
statsObserver.observe(stat);
});
// Form validation (if needed in future)
const forms = document.querySelectorAll('form');
forms.forEach(form => {
form.addEventListener('submit', (e) => {
const inputs = form.querySelectorAll('input[required], textarea[required]');
let isValid = true;
inputs.forEach(input => {
if (!input.value.trim()) {
isValid = false;
input.style.borderColor = '#ff5f56';
} else {
input.style.borderColor = '';
}
});
if (!isValid) {
e.preventDefault();
alert('Please fill in all required fields');
}
});
});
// Add hover effect for cards
const cards = document.querySelectorAll('.feature-card, .info-card, .resource-card, .step-card');
cards.forEach(card => {
card.addEventListener('mouseenter', function() {
this.style.transition = 'all 0.3s cubic-bezier(0.4, 0, 0.2, 1)';
});
});
// Lazy loading for images (if added later)
if ('IntersectionObserver' in window) {
const imageObserver = new IntersectionObserver((entries) => {
entries.forEach(entry => {
if (entry.isIntersecting) {
const img = entry.target;
if (img.dataset.src) {
img.src = img.dataset.src;
img.removeAttribute('data-src');
imageObserver.unobserve(img);
}
}
});
});
const lazyImages = document.querySelectorAll('img[data-src]');
lazyImages.forEach(img => imageObserver.observe(img));
}
// Preloader (optional)
window.addEventListener('load', () => {
const preloader = document.querySelector('.preloader');
if (preloader) {
preloader.style.opacity = '0';
setTimeout(() => {
preloader.style.display = 'none';
}, 300);
}
});
// Add ripple effect to buttons
const buttons = document.querySelectorAll('.btn, .btn-primary, .btn-secondary, .btn-form, .btn-download-large');
buttons.forEach(button => {
button.addEventListener('click', function(e) {
const ripple = document.createElement('span');
const rect = this.getBoundingClientRect();
const size = Math.max(rect.width, rect.height);
const x = e.clientX - rect.left - size / 2;
const y = e.clientY - rect.top - size / 2;
ripple.style.width = ripple.style.height = size + 'px';
ripple.style.left = x + 'px';
ripple.style.top = y + 'px';
ripple.style.position = 'absolute';
ripple.style.borderRadius = '50%';
ripple.style.background = 'rgba(255, 255, 255, 0.6)';
ripple.style.transform = 'scale(0)';
ripple.style.animation = 'ripple 0.6s ease-out';
ripple.style.pointerEvents = 'none';
this.style.position = 'relative';
this.style.overflow = 'hidden';
this.appendChild(ripple);
setTimeout(() => {
ripple.remove();
}, 600);
});
});
// Add ripple animation to CSS dynamically
const style = document.createElement('style');
style.textContent = `
@keyframes ripple {
to {
transform: scale(4);
opacity: 0;
}
}
`;
document.head.appendChild(style);
// Console message
console.log('%c Redux Toolkit Website ', 'background: #441E59; color: #FCFA50; font-size: 20px; padding: 10px; border-radius: 5px;');
console.log('%c Designed & Developed with ❤️ by Factory Droid ', 'background: #FCFA50; color: #441E59; font-size: 14px; padding: 5px; border-radius: 3px;');