-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
193 lines (153 loc) · 6.31 KB
/
Copy pathscript.js
File metadata and controls
193 lines (153 loc) · 6.31 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
// --- Floating Emojis Global Interaction ---
const emojis = ['🌸', '✨', '💖', '🥺', '💍', '😡'];
const emojiContainer = document.getElementById('emoji-container');
function createEmoji() {
const el = document.createElement('div');
el.className = 'floating-emoji';
el.innerText = emojis[Math.floor(Math.random() * emojis.length)];
// Randomize initial horizontal position
el.style.left = (Math.random() * 90 + 5) + 'vw';
// Randomize size
const size = Math.random() * 24 + 16; // 16px to 40px
el.style.fontSize = size + 'px';
// Randomize duration (5s to 12s)
const duration = Math.random() * 7 + 5;
el.style.animationDuration = duration + 's';
// Randomize slight wiggle via animation delay
el.style.animationDelay = (Math.random() * 0.5) + 's';
emojiContainer.appendChild(el);
// Cleanup
setTimeout(() => {
if (emojiContainer.contains(el)) {
el.remove();
}
}, (duration + 1) * 1000);
}
// Generate an emoji periodically
setInterval(createEmoji, 450);
// Generate a few initially
for(let i=0; i<5; i++) setTimeout(createEmoji, i * 200);
// --- Page State Management ---
function nextPage(pageNumber) {
const container = document.getElementById('glass-container');
// Create a slight pulse effect on the container
container.style.transform = 'scale(0.98)';
// Hide active pages
document.querySelectorAll('.page-content').forEach(page => {
if (page.classList.contains('active')) {
page.classList.remove('active');
setTimeout(() => {
page.classList.add('hidden');
page.style.display = 'none'; // Ensure layout collapses
// Show requested page after previous hides
const next = document.getElementById(`page-${pageNumber}`);
next.classList.remove('hidden');
next.style.display = 'flex';
// Allow browser redraw before adding active class for animation
requestAnimationFrame(() => {
requestAnimationFrame(() => {
next.classList.add('active');
container.style.transform = 'scale(1)';
});
});
}, 600); // Matches CSS transition duration
}
});
}
// --- Escape Button Logic ('No' Button) ---
const btnNo = document.getElementById('btn-no');
// Move button away when cursor approaches
btnNo.addEventListener('mouseenter', escapeCursor);
// Also trigger on touch devices to prevent tapping
btnNo.addEventListener('touchstart', (e) => {
e.preventDefault();
escapeCursor(e);
}, { passive: false });
function escapeCursor(e) {
const btn = btnNo;
// If it hasn't been detached from the normal document flow yet, detach it
if (btn.style.position !== 'fixed') {
const rect = btn.getBoundingClientRect();
btn.style.position = 'fixed';
btn.style.left = rect.left + 'px';
btn.style.top = rect.top + 'px';
btn.style.margin = '0'; // Remove any margins
document.body.appendChild(btn); // Move to body context to fly anywhere
// Force reflow
btn.getBoundingClientRect();
}
const btnRect = btn.getBoundingClientRect();
const btnCenterX = btnRect.left + btnRect.width / 2;
const btnCenterY = btnRect.top + btnRect.height / 2;
let cursorX = e.clientX || (e.touches && e.touches[0].clientX) || btnCenterX;
let cursorY = e.clientY || (e.touches && e.touches[0].clientY) || btnCenterY;
// Calculate direction vector from cursor TO button
let dirX = btnCenterX - cursorX;
let dirY = btnCenterY - cursorY;
// If exact same spot (rare), pick random direction
const magnitude = Math.sqrt(dirX * dirX + dirY * dirY);
if (magnitude < 1) {
dirX = (Math.random() - 0.5) * 2;
dirY = (Math.random() - 0.5) * 2;
} else {
dirX /= magnitude;
dirY /= magnitude;
}
const moveDist = 200; // Jump distance in pixels
let newX = btnRect.left + dirX * moveDist;
let newY = btnRect.top + dirY * moveDist;
// Boundary checks (keep fully inside viewport)
const maxW = window.innerWidth - btnRect.width - 20;
const maxH = window.innerHeight - btnRect.height - 20;
// Bounce inward if hitting edge
if (newX < 20) newX = Math.random() * 100 + 50;
if (newX > maxW) newX = maxW - (Math.random() * 100 + 50);
if (newY < 20) newY = Math.random() * 100 + 50;
if (newY > maxH) newY = maxH - (Math.random() * 100 + 50);
btn.style.left = newX + 'px';
btn.style.top = newY + 'px';
}
// --- Accept Proposal Logic ---
function acceptProposal() {
// 1. Massive Confetti Explosion
const duration = 8 * 1000;
const animationEnd = Date.now() + duration;
const defaults = { startVelocity: 45, spread: 360, ticks: 100, zIndex: 1000 };
function randomInRange(min, max) {
return Math.random() * (max - min) + min;
}
const interval = setInterval(function() {
const timeLeft = animationEnd - Date.now();
if (timeLeft <= 0) {
return clearInterval(interval);
}
const particleCount = 80 * (timeLeft / duration);
// Fire from both bottom edges
confetti(Object.assign({}, defaults, {
particleCount,
origin: { x: randomInRange(0.1, 0.3), y: Math.random() - 0.2 }
}));
confetti(Object.assign({}, defaults, {
particleCount,
origin: { x: randomInRange(0.7, 0.9), y: Math.random() - 0.2 }
}));
}, 250);
// Initial blast
confetti({
particleCount: 200,
spread: 120,
origin: { y: 0.6 },
colors: ['#ffe4e6', '#fda4af', '#f43f5e', '#e11d48']
});
// 2. Show Celebration Overlay
const overlay = document.getElementById('celebration-overlay');
overlay.classList.remove('hidden');
overlay.classList.add('flex');
// Trigger fade in
setTimeout(() => {
overlay.classList.add('opacity-100');
overlay.classList.remove('opacity-0');
// Add heartbeat animation to content
document.getElementById('celebration-content').classList.add('heart-beat');
}, 50);
}