-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
243 lines (207 loc) · 8.48 KB
/
script.js
File metadata and controls
243 lines (207 loc) · 8.48 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
// Mobile Navigation Toggle
document.addEventListener('DOMContentLoaded', function() {
const navToggle = document.querySelector('.nav-toggle');
const navMenu = document.querySelector('.nav-menu');
const navLinks = document.querySelectorAll('.nav-link');
// Toggle mobile menu
navToggle.addEventListener('click', function() {
navMenu.classList.toggle('active');
// Animate hamburger menu
const bars = navToggle.querySelectorAll('.bar');
bars.forEach((bar, index) => {
if (navMenu.classList.contains('active')) {
if (index === 0) bar.style.transform = 'rotate(-45deg) translate(-5px, 6px)';
if (index === 1) bar.style.opacity = '0';
if (index === 2) bar.style.transform = 'rotate(45deg) translate(-5px, -6px)';
} else {
bar.style.transform = '';
bar.style.opacity = '';
}
});
});
// Close mobile menu when clicking on links
navLinks.forEach(link => {
link.addEventListener('click', function() {
navMenu.classList.remove('active');
const bars = navToggle.querySelectorAll('.bar');
bars.forEach(bar => {
bar.style.transform = '';
bar.style.opacity = '';
});
});
});
// Smooth scrolling for anchor links
document.querySelectorAll('a[href^="#"]').forEach(anchor => {
anchor.addEventListener('click', function (e) {
e.preventDefault();
const target = document.querySelector(this.getAttribute('href'));
if (target) {
const headerOffset = 70;
const elementPosition = target.getBoundingClientRect().top;
const offsetPosition = elementPosition + window.pageYOffset - headerOffset;
window.scrollTo({
top: offsetPosition,
behavior: 'smooth'
});
}
});
});
// Navbar background on scroll
window.addEventListener('scroll', function() {
const navbar = document.querySelector('.navbar');
if (window.scrollY > 50) {
navbar.style.background = 'rgba(255, 255, 255, 0.98)';
navbar.style.boxShadow = '0 2px 20px rgba(0, 0, 0, 0.1)';
} else {
navbar.style.background = 'rgba(255, 255, 255, 0.95)';
navbar.style.boxShadow = 'none';
}
});
// Animate elements on scroll
const observerOptions = {
threshold: 0.1,
rootMargin: '0px 0px -50px 0px'
};
const observer = new IntersectionObserver(function(entries) {
entries.forEach(entry => {
if (entry.isIntersecting) {
entry.target.style.opacity = '1';
entry.target.style.transform = 'translateY(0)';
}
});
}, observerOptions);
// Observe elements for animation
const animateElements = document.querySelectorAll('.feature-card, .team-member, .community-card, .arch-component');
animateElements.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);
});
// Counter animation for stats
function animateCounter(element, target, duration = 2000) {
let start = 0;
const increment = target / (duration / 16);
function updateCounter() {
start += increment;
if (start < target) {
element.textContent = Math.floor(start);
requestAnimationFrame(updateCounter);
} else {
element.textContent = target;
}
}
updateCounter();
}
// Animate stats when they come into view
const statsObserver = new IntersectionObserver(function(entries) {
entries.forEach(entry => {
if (entry.isIntersecting) {
const statNumber = entry.target.querySelector('.stat-number');
const text = statNumber.textContent;
// Extract number from text like "60%" or "$100B+"
const number = parseInt(text.replace(/[^\d]/g, ''));
if (!isNaN(number) && number > 0) {
statNumber.textContent = '0' + text.replace(/\d+/, '');
animateCounter(statNumber, number);
// Add back the suffix after animation
setTimeout(() => {
statNumber.textContent = text;
}, 2000);
}
statsObserver.unobserve(entry.target);
}
});
}, { threshold: 0.5 });
document.querySelectorAll('.stat').forEach(stat => {
statsObserver.observe(stat);
});
// Blockchain animation enhancement
const blocks = document.querySelectorAll('.block');
blocks.forEach((block, index) => {
block.addEventListener('mouseenter', function() {
this.style.transform = 'scale(1.1) translateY(-5px)';
this.style.boxShadow = '0 15px 40px rgba(102, 126, 234, 0.4)';
});
block.addEventListener('mouseleave', function() {
this.style.transform = '';
this.style.boxShadow = '0 10px 30px rgba(102, 126, 234, 0.3)';
});
});
// Copy to clipboard functionality for code snippets (if any)
document.querySelectorAll('.copy-btn').forEach(btn => {
btn.addEventListener('click', function() {
const code = this.parentElement.querySelector('code');
if (code) {
navigator.clipboard.writeText(code.textContent).then(() => {
this.textContent = 'Copied!';
setTimeout(() => {
this.textContent = 'Copy';
}, 2000);
});
}
});
});
// Form handling (if contact form is added later)
const forms = document.querySelectorAll('form');
forms.forEach(form => {
form.addEventListener('submit', function(e) {
e.preventDefault();
// Add form submission logic here
console.log('Form submitted');
});
});
// Easter egg: Konami code
let konamiCode = [];
const konamiSequence = [38, 38, 40, 40, 37, 39, 37, 39, 66, 65]; // Up Up Down Down Left Right Left Right B A
document.addEventListener('keydown', function(e) {
konamiCode.push(e.keyCode);
if (konamiCode.length > konamiSequence.length) {
konamiCode.shift();
}
if (JSON.stringify(konamiCode) === JSON.stringify(konamiSequence)) {
// Easter egg activated
document.body.style.filter = 'hue-rotate(180deg)';
setTimeout(() => {
document.body.style.filter = '';
}, 3000);
konamiCode = [];
}
});
// Performance optimization: Lazy load images when added
if ('IntersectionObserver' in window) {
const imageObserver = new IntersectionObserver((entries, observer) => {
entries.forEach(entry => {
if (entry.isIntersecting) {
const img = entry.target;
img.src = img.dataset.src;
img.classList.remove('lazy');
imageObserver.unobserve(img);
}
});
});
document.querySelectorAll('img[data-src]').forEach(img => {
imageObserver.observe(img);
});
}
// Add loading state for external links
document.querySelectorAll('a[target="_blank"]').forEach(link => {
link.addEventListener('click', function() {
const originalText = this.innerHTML;
this.innerHTML = '<i class="fas fa-spinner fa-spin"></i> Opening...';
setTimeout(() => {
this.innerHTML = originalText;
}, 1000);
});
});
// Add subtle parallax effect to hero section
window.addEventListener('scroll', function() {
const scrolled = window.pageYOffset;
const heroVisual = document.querySelector('.hero-visual');
if (heroVisual && scrolled < window.innerHeight) {
heroVisual.style.transform = `translateY(${scrolled * 0.3}px)`;
}
});
console.log('🚗 Clutch Protocol website loaded successfully!');
console.log('💡 Built with modern web technologies for the decentralized future');
});