-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
184 lines (159 loc) · 6.16 KB
/
script.js
File metadata and controls
184 lines (159 loc) · 6.16 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
// ==========================================
// Email Form Handling with Formspree
// ==========================================
document.addEventListener('DOMContentLoaded', function () {
const form = document.getElementById('notifyForm');
const emailInput = document.getElementById('email');
const formMessage = document.getElementById('formMessage');
form.addEventListener('submit', function (e) {
e.preventDefault();
const email = emailInput.value.trim();
// Basic email validation
if (!isValidEmail(email)) {
showMessage('Please enter a valid email address', 'error');
return;
}
// Submit to Formspree
submitEmail(email);
});
function isValidEmail(email) {
const emailRegex = /^[^\s@]+@[^\s@]+\.[^\s@]+$/;
return emailRegex.test(email);
}
function submitEmail(email) {
// Show loading state
const submitBtn = form.querySelector('.btn-primary');
const originalText = submitBtn.textContent;
submitBtn.textContent = 'Submitting...';
submitBtn.disabled = true;
// Submit to Formspree
fetch(form.action, {
method: 'POST',
body: new FormData(form),
headers: {
'Accept': 'application/json'
}
})
.then(response => {
if (response.ok) {
showMessage('Thanks! We\'ll notify you when we launch! 🎉', 'success');
emailInput.value = '';
// Also store locally for backup
try {
let subscribers = JSON.parse(localStorage.getItem('dtf_subscribers') || '[]');
if (!subscribers.includes(email)) {
subscribers.push(email);
localStorage.setItem('dtf_subscribers', JSON.stringify(subscribers));
}
} catch (e) {
// Silent fail for localStorage
}
} else {
response.json().then(data => {
if (data.errors) {
showMessage('Oops! ' + data.errors.map(e => e.message).join(', '), 'error');
} else {
showMessage('Oops! Something went wrong. Please try again.', 'error');
}
});
}
})
.catch(error => {
showMessage('Oops! Something went wrong. Please try again.', 'error');
})
.finally(() => {
// Reset button
submitBtn.textContent = originalText;
submitBtn.disabled = false;
});
}
function showMessage(message, type) {
formMessage.textContent = message;
formMessage.className = 'form-message ' + type;
// Add animation
formMessage.style.animation = 'none';
setTimeout(() => {
formMessage.style.animation = 'fadeInUp 0.4s ease-out';
}, 10);
}
});
// ==========================================
// Page Load Animations
// ==========================================
window.addEventListener('load', function () {
// Add loaded class for any additional animations
document.body.classList.add('loaded');
});
// ==========================================
// Optional: Add parallax effect to logo on scroll
// ==========================================
let lastScrollY = window.scrollY;
window.addEventListener('scroll', function () {
const logo = document.querySelector('.logo');
const scrollY = window.scrollY;
// Subtle parallax effect
if (logo) {
logo.style.transform = `translateY(${scrollY * 0.3}px)`;
}
lastScrollY = scrollY;
}, { passive: true });
// ==========================================
// Easter Egg: Click logo for fun animation
// ==========================================
document.addEventListener('DOMContentLoaded', function () {
const logo = document.querySelector('.logo');
let clickCount = 0;
if (logo) {
logo.addEventListener('click', function () {
clickCount++;
// Add bounce animation
this.style.animation = 'none';
setTimeout(() => {
this.style.animation = 'float 6s ease-in-out infinite, bounce 0.5s ease';
}, 10);
// Special effect after 5 clicks
if (clickCount === 5) {
createConfetti();
clickCount = 0;
}
});
}
});
function createConfetti() {
const colors = ['#7EC8E3', '#FFD700', '#F5F1E8', '#5BA8C8'];
const confettiCount = 50;
for (let i = 0; i < confettiCount; i++) {
const confetti = document.createElement('div');
confetti.style.position = 'fixed';
confetti.style.width = '10px';
confetti.style.height = '10px';
confetti.style.backgroundColor = colors[Math.floor(Math.random() * colors.length)];
confetti.style.left = Math.random() * 100 + '%';
confetti.style.top = '-10px';
confetti.style.opacity = '1';
confetti.style.borderRadius = '50%';
confetti.style.pointerEvents = 'none';
confetti.style.zIndex = '9999';
document.body.appendChild(confetti);
const duration = Math.random() * 3 + 2;
const xMovement = (Math.random() - 0.5) * 200;
confetti.animate([
{ transform: 'translateY(0) translateX(0) rotate(0deg)', opacity: 1 },
{ transform: `translateY(100vh) translateX(${xMovement}px) rotate(${Math.random() * 360}deg)`, opacity: 0 }
], {
duration: duration * 1000,
easing: 'cubic-bezier(0.25, 0.46, 0.45, 0.94)'
}).onfinish = () => confetti.remove();
}
}
// Add bounce animation to CSS dynamically
const style = document.createElement('style');
style.textContent = `
@keyframes bounce {
0%, 100% { transform: translateY(0); }
25% { transform: translateY(-20px); }
50% { transform: translateY(0); }
75% { transform: translateY(-10px); }
}
`;
document.head.appendChild(style);