-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
224 lines (183 loc) · 5.74 KB
/
Copy pathscript.js
File metadata and controls
224 lines (183 loc) · 5.74 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
const screen1 = document.getElementById('screen1');
const screen2 = document.getElementById('screen2');
const confettiLayer = document.getElementById('confetti');
const arena = document.getElementById('arena');
const yesBtn = document.getElementById('yesBtn');
const noBtn = document.getElementById('noBtn');
let dodgeCount = 0;
let endMode = false;
let noStartLeft = 0;
// 10 simple phases (short)
const phases = [
"No 💔",
"Nope 🙅♀️",
"Nah 😤",
"Hmm 🤔",
"Stop 🙈",
"Hey 😭",
"Uh 😳",
"Wait 👀",
"Maybe 💘",
"Fine 💞"
];
// end animation: No -> Yes -> No -> Yes -> Yes
const endCycle = ["No 💔", "Yes 💚", "No 💔", "Yes 💚", "Yes 💚"];
function placeSideBySide(){
const w = arena.clientWidth;
const gap = 14;
// reset to baseline position before measuring
yesBtn.style.top = "50%";
noBtn.style.top = "50%";
const yesW = yesBtn.offsetWidth;
const noW = noBtn.offsetWidth;
const total = yesW + gap + noW;
const leftStart = (w - total) / 2;
yesBtn.style.left = leftStart + "px";
noBtn.style.left = (leftStart + yesW + gap) + "px";
noStartLeft = parseFloat(noBtn.style.left);
}
function burstConfetti(){
const colors = ["#22c55e","#ef4444","#111827","#f59e0b","#3b82f6","#ec4899"];
const count = 160;
for (let i=0; i<count; i++){
const piece = document.createElement('i');
piece.style.left = (Math.random()*100) + "vw";
piece.style.width = (6 + Math.random()*8) + "px";
piece.style.height = (10 + Math.random()*14) + "px";
piece.style.background = colors[Math.floor(Math.random()*colors.length)];
piece.style.animationDuration = (1.6 + Math.random()*1.6) + "s";
confettiLayer.appendChild(piece);
setTimeout(() => piece.remove(), 3500);
}
}
function goNext(){
burstConfetti();
setTimeout(() => {
screen1.classList.add('hidden');
screen2.classList.remove('hidden');
}, 250);
}
function shakeNo(){
noBtn.classList.remove('shaking');
void noBtn.offsetWidth;
noBtn.classList.add('shaking');
}
// iPhone-safe, big-space movement: within the card but below header area
function moveNoRandom(){
const pad = 10;
const container = screen1.getBoundingClientRect();
const bw = noBtn.offsetWidth;
const bh = noBtn.offsetHeight;
// Avoid the top header area on small screens
// (roughly: title + subtitle region)
const headerSafeY = Math.min(150, container.height * 0.28);
const minX = pad;
const maxX = Math.max(pad, container.width - bw - pad);
const minY = headerSafeY;
const maxY = Math.max(headerSafeY, container.height - bh - pad);
const x = minX + Math.random() * (maxX - minX);
const y = minY + Math.random() * (maxY - minY);
// Convert to arena-relative positioning (button stays inside the card visually)
const arenaRect = arena.getBoundingClientRect();
const left = x - (arenaRect.left - container.left);
const top = y - (arenaRect.top - container.top);
noBtn.style.transition = "left 0.18s cubic-bezier(.34,1.56,.64,1), top 0.18s cubic-bezier(.34,1.56,.64,1)";
noBtn.style.left = left + "px";
noBtn.style.top = top + "px";
noBtn.classList.remove("panic");
void noBtn.offsetWidth;
noBtn.classList.add("panic");
}
function finalizeNoAtStartAndCycle(){
endMode = true;
noBtn.style.left = noStartLeft + "px";
noBtn.style.top = "50%";
let i = 0;
const tick = () => {
const text = endCycle[Math.min(i, endCycle.length - 1)];
noBtn.textContent = text;
if (text.includes("Yes")) {
noBtn.classList.remove('no');
noBtn.classList.add('yes');
} else {
noBtn.classList.remove('yes');
noBtn.classList.add('no');
}
i++;
if (i < endCycle.length) {
setTimeout(tick, 220);
} else {
noBtn.textContent = "Yes 💚";
noBtn.classList.remove('no');
noBtn.classList.add('yes');
}
};
tick();
}
function onTryNo(){
// After end: both buttons go next
if (endMode) return goNext();
dodgeCount++;
noBtn.textContent = phases[Math.min(phases.length - 1, dodgeCount - 1)];
// small shake a couple times
if (dodgeCount === 3 || dodgeCount === 6) shakeNo();
if (dodgeCount >= 10){
finalizeNoAtStartAndCycle();
return;
}
// more drama later: double hop
const hops = dodgeCount >= 7 ? 2 : 1;
for (let i = 0; i < hops; i++) {
setTimeout(moveNoRandom, i * 110);
}
}
// Navigation rules:
// - Before end: ONLY YES goes next
// - After end: BOTH buttons go next
yesBtn.addEventListener('click', () => {
if (endMode) return goNext();
goNext();
});
// iPhone: use touch/pointer events so "hover dodge" still works via tap
noBtn.addEventListener('click', () => {
if (endMode) return goNext();
onTryNo();
});
// Desktop hover
noBtn.addEventListener('mouseenter', () => {
if (endMode) return;
onTryNo();
});
// iOS quick tap triggers immediately (prevents 300ms delay / weirdness)
noBtn.addEventListener('touchstart', (e) => {
if (endMode) return;
e.preventDefault();
onTryNo();
}, { passive: false });
noBtn.addEventListener('pointerdown', (e) => {
// On iOS Safari this fires; keeps it responsive
if (endMode) return;
if (e.pointerType === "touch") {
e.preventDefault();
onTryNo();
}
}, { passive: false });
// Keep the mouse “proximity dodge” on desktop only
arena.addEventListener('pointermove', (e) => {
if (endMode) return;
if (e.pointerType !== "mouse") return;
const btn = noBtn.getBoundingClientRect();
const dist = Math.hypot(
e.clientX - (btn.left + btn.width/2),
e.clientY - (btn.top + btn.height/2)
);
if (dist < 90) {
if (!noBtn.dataset.cooldown) {
noBtn.dataset.cooldown = "1";
onTryNo();
setTimeout(() => delete noBtn.dataset.cooldown, 170);
}
}
});
window.addEventListener('load', placeSideBySide);
window.addEventListener('resize', placeSideBySide);