-
Notifications
You must be signed in to change notification settings - Fork 24
Expand file tree
/
Copy pathindex.html
More file actions
599 lines (531 loc) · 17 KB
/
index.html
File metadata and controls
599 lines (531 loc) · 17 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
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
<!DOCTYPE html>
<html lang="zh-CN">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>测测你是不是猪</title>
<!-- Tailwind CSS v3 -->
<script src="https://cdn.tailwindcss.com"></script>
<script>
tailwind.config = {
theme: {
extend: {
colors: {
primary: '#FFB6C1', // 浅粉色
secondary: '#F5F5F5', // 浅灰色
accent: '#FF69B4', // 亮粉色
},
fontFamily: {
sans: ['Arial Rounded MT Bold', 'Avenir', 'Helvetica', 'Arial', 'sans-serif'],
},
animation: {
'bounce-slow': 'bounce 2s infinite',
'wiggle': 'wiggle 1s ease-in-out infinite',
'pulse-slow': 'pulse 3s infinite',
},
keyframes: {
wiggle: {
'0%, 100%': { transform: 'rotate(-3deg)' },
'50%': { transform: 'rotate(3deg)' },
}
}
}
}
}
</script>
<style type="text/tailwindcss">
@layer utilities {
.text-shadow {
text-shadow: 0 2px 4px rgba(0,0,0,0.1);
}
.text-shadow-lg {
text-shadow: 0 4px 8px rgba(0,0,0,0.12), 0 2px 4px rgba(0,0,0,0.08);
}
.progress-ring-circle {
transition: stroke-dashoffset 0.35s;
transform: rotate(-90deg);
transform-origin: 50% 50%;
}
}
body {
touch-action: none; /* 防止长按弹出菜单 */
user-select: none; /* 防止文本选择 */
-webkit-tap-highlight-color: transparent; /* 移除点击高亮 */
}
.result-card {
transform-style: preserve-3d;
transition: transform 0.6s;
}
.result-card.flipped {
transform: rotateY(180deg);
}
.result-card-front, .result-card-back {
backface-visibility: hidden;
position: absolute;
top: 0;
left: 0;
width: 100%;
height: 100%;
}
.result-card-back {
transform: rotateY(180deg);
}
@keyframes float {
0% { transform: translateY(0px); }
50% { transform: translateY(-10px); }
100% { transform: translateY(0px); }
}
.float-animation {
animation: float 3s ease-in-out infinite;
}
.progress-container {
position: relative;
width: 200px;
height: 200px;
}
.progress-ring {
transform: rotate(-90deg);
}
.progress-text {
position: absolute;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
font-size: 1.5rem;
font-weight: bold;
}
.press-hint {
position: absolute;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
text-align: center;
pointer-events: none;
}
</style>
</head>
<body class="bg-secondary min-h-screen flex flex-col items-center justify-center p-4">
<div class="container max-w-md mx-auto text-center">
<!-- 标题 -->
<h1 class="text-4xl md:text-5xl font-bold mb-6 text-primary text-shadow-lg">
测测你是不是猪 <span class="text-accent">🐷</span>
</h1>
<!-- 主内容区 -->
<div class="bg-white rounded-3xl shadow-lg p-6 mb-8 transform transition-all duration-300 hover:shadow-xl">
<!-- 测试区域 -->
<div id="test-area" class="mb-6">
<div class="progress-container mx-auto">
<!-- 圆形进度条 -->
<svg class="progress-ring" width="200" height="200">
<circle
class="text-gray-200"
stroke-width="10"
stroke="currentColor"
fill="transparent"
r="85"
cx="100"
cy="100"
/>
<circle
id="progress-circle"
class="text-primary progress-ring-circle"
stroke-width="10"
stroke="currentColor"
fill="transparent"
r="85"
cx="100"
cy="100"
stroke-dasharray="534.07"
stroke-dashoffset="534.07"
/>
</svg>
<!-- 长按提示 -->
<div id="press-hint" class="press-hint">
<div class="text-5xl mb-2">👇</div>
<p class="text-lg text-gray-600">长按这里测试</p>
</div>
<!-- 进度文本 -->
<div id="progress-text" class="progress-text hidden">
<span id="progress-percentage">0%</span>
</div>
</div>
<!-- 提示文字 -->
<p id="instruction" class="text-gray-600 mt-6">
长按屏幕中间区域,看看你是什么猪!
</p>
</div>
<!-- 结果区域 (初始隐藏) -->
<div id="result-area" class="hidden">
<div class="bg-primary/10 rounded-2xl p-6 flex flex-col items-center justify-center h-64 mb-6">
<img id="result-emoji" class="w-24 h-24 mb-4 float-animation" src="image/pig.png" alt="猪">
<h2 id="result-title" class="text-2xl font-bold text-gray-800 mb-2">猪</h2>
<p id="result-description" class="text-gray-600">
你是一只可爱的小猪猪!
</p>
</div>
<button id="retest-button" class="hidden bg-primary text-white py-2 px-6 rounded-full font-medium mb-4 hover:bg-primary/80 transition-colors">
重新测试
</button>
<p class="text-gray-500 text-sm">
提示:结果已保存,刷新不会改变哦!
</p>
</div>
</div>
<!-- 页脚 -->
<footer class="text-gray-500 text-sm">
<p>作者:nanan <span class="text-primary">🐽</span></p>
</footer>
</div>
<script>
// 结果数据
const pigResults = [
{
id: "human",
name: "人类",
emoji: "👤",
description: "检测不出猪元素,是人类吗?",
analysis: ""
},
{
id: "pig",
name: "猪",
emoji: "🐷",
description: "普通小猪",
analysis: ""
},
{
id: "black-pig",
name: "小黑猪",
emoji: "🐖",
description: "小黑猪,卤出猪脚了",
analysis: ""
},
{
id: "wild-boar",
name: "野猪",
emoji: "🐗",
description: "你是一只勇猛的野猪!",
analysis: ""
},
{
id: "zhuge-liang",
name: "猪葛亮",
emoji: "🐷🧠",
description: "猪里最聪明的一个",
analysis: ""
},
{
id: "pig-stamp",
name: "猪圆章",
emoji: "🐷🔴",
description: "《猪圈那些事》",
analysis: ""
},
{
id: "zombie-pig",
name: "僵尸猪",
emoji: "🧟🐷",
description: "喜欢的食物是猪脑",
analysis: ""
},
{
id: "skeleton-pig",
name: "骷髅猪",
emoji: "💀🐷",
description: "资深不死族",
analysis: ""
},
{
id: "pig-human",
name: "猪人",
emoji: "🐷👤",
description: "你是猪还是人?",
analysis: ""
},
{
id: "demon-pig",
name: "恶魔猪",
emoji: "😈🐷",
description: "满肚子坏心眼",
analysis: ""
},
{
id: "heaven-pig",
name: "天堂猪",
emoji: "😇🐷",
description: "似了喵~",
analysis: ""
},
{
id: "explosive-pig",
name: "爆破小猪",
emoji: "💣🐷",
description: "我跟你爆了!",
analysis: ""
},
{
id: "black-white-pig",
name: "黑白猪",
emoji: "⚫⚪🐷",
description: "串子",
analysis: ""
},
{
id: "pork-skewer",
name: "猪肉串",
emoji: "🍢",
description: "真正的串子",
analysis: ""
},
{
id: "magic-pig",
name: "魔法少猪",
emoji: "🪄🐷",
description: "马猪烧酒",
analysis: ""
},
{
id: "mechanical-pig",
name: "机械猪",
emoji: "🤖🐷",
description: "人机",
analysis: ""
},
{
id: "pig-ball",
name: "猪猪球",
emoji: "🏀🐷",
description: "滚了",
analysis: ""
},
{
id: "doll-pig",
name: "玩偶猪",
emoji: "🧸🐷",
description: "fufu小猪",
analysis: ""
},
{
id: "soul-pig",
name: "灵魂猪",
emoji: "👻🐷",
description: "从冥界归来的猪",
analysis: ""
},
{
id: "crystal-pig",
name: "水晶猪",
emoji: "💎🐷",
description: "珍贵又脆弱的小猪",
analysis: ""
},
{
id: "snow-pig",
name: "雪猪",
emoji: "❄️🐷",
description: "洁白的雪猪",
analysis: ""
},
{
id: "pig-cat",
name: "猪咪",
emoji: "🐷🐱",
description: "你是一只可爱的猪咪!",
analysis: ""
}
];
// DOM 元素
const testArea = document.getElementById('test-area');
const resultArea = document.getElementById('result-area');
const progressCircle = document.getElementById('progress-circle');
const progressText = document.getElementById('progress-text');
const progressPercentage = document.getElementById('progress-percentage');
const pressHint = document.getElementById('press-hint');
const instruction = document.getElementById('instruction');
const resultEmoji = document.getElementById('result-emoji');
const resultTitle = document.getElementById('result-title');
const resultDescription = document.getElementById('result-description');
const retestButton = document.getElementById('retest-button');
// 进度条参数
const circumference = 2 * Math.PI * 85; // 圆的周长
const requiredHoldTime = 3000; // 长按所需时间(毫秒)
let startTime = 0;
let isHolding = false;
let progressInterval;
// 初始化进度条
progressCircle.style.strokeDasharray = `${circumference} ${circumference}`;
progressCircle.style.strokeDashoffset = circumference;
// 检查是否已有结果
let savedResult = null;
try {
savedResult = localStorage.getItem('pigTestResult');
if (savedResult) {
showResult(JSON.parse(savedResult));
}
} catch (error) {
console.error('读取本地存储失败:', error);
// 清除可能损坏的数据
localStorage.removeItem('pigTestResult');
savedResult = null;
}
// 长按开始事件
function handleHoldStart(e) {
// 阻止默认行为
e.preventDefault();
// 如果已有结果,不执行任何操作
if (localStorage.getItem('pigTestResult')) return;
isHolding = true;
startTime = Date.now();
// 显示进度条
progressText.classList.remove('hidden');
pressHint.classList.add('hidden');
instruction.textContent = '正在测试中...';
// 开始更新进度条
progressInterval = setInterval(updateProgress, 30);
// 添加视觉反馈
testArea.classList.add('scale-105');
testArea.style.transition = 'transform 0.2s';
}
// 长按结束事件
function handleHoldEnd() {
// 如果已有结果,不执行任何操作
if (localStorage.getItem('pigTestResult')) return;
isHolding = false;
clearInterval(progressInterval);
// 重置进度条
resetProgress();
// 恢复视觉效果
testArea.classList.remove('scale-105');
instruction.textContent = '将手指放到屏幕中间区域,长按汲取猪元素';
}
// 更新进度条
function updateProgress() {
if (!isHolding) return;
const elapsedTime = Date.now() - startTime;
const progress = Math.min(elapsedTime / requiredHoldTime, 1);
const offset = circumference - (progress * circumference);
// 更新进度条
progressCircle.style.strokeDashoffset = offset;
// 更新百分比文本
const percentage = Math.round(progress * 100);
progressPercentage.textContent = `${percentage}%`;
// 如果达到100%,生成结果
if (progress >= 1) {
clearInterval(progressInterval);
generateResult();
}
}
// 重置进度条
function resetProgress() {
clearInterval(progressInterval);
progressCircle.style.strokeDashoffset = circumference;
progressText.classList.add('hidden');
pressHint.classList.remove('hidden');
progressPercentage.textContent = '0%';
}
// 生成随机结果
function generateResult() {
try {
// 播放完成音效
playSound('complete');
// 随机选择一个结果
const randomIndex = Math.floor(Math.random() * pigResults.length);
const result = pigResults[randomIndex];
// 保存结果到本地存储
localStorage.setItem('pigTestResult', JSON.stringify(result));
// 显示结果
showResult(result);
} catch (error) {
console.error('生成结果失败:', error);
alert('生成结果失败,请重试!');
// 重置界面
resetProgress();
instruction.textContent = '长按屏幕中间区域,看看你是什么猪!';
}
}
// 显示结果
function showResult(result) {
// 隐藏测试区域,显示结果区域
testArea.classList.add('hidden');
resultArea.classList.remove('hidden');
// 设置结果内容
const imageSrc = `image/${result.id}.png`;
resultEmoji.src = imageSrc;
resultEmoji.alt = result.name;
resultTitle.textContent = result.name;
resultDescription.textContent = result.description;
// 添加图片加载失败处理
resultEmoji.onerror = function() {
// 如果图片加载失败,使用默认图片
resultEmoji.src = 'image/pig.png';
};
// 添加结果出现动画
resultArea.style.opacity = '0';
resultArea.style.transform = 'translateY(20px)';
resultArea.style.transition = 'opacity 0.5s, transform 0.5s';
setTimeout(() => {
resultArea.style.opacity = '1';
resultArea.style.transform = 'translateY(0)';
}, 10);
}
// 播放音效
function playSound(type) {
try {
// 创建音频上下文
const AudioContext = window.AudioContext || window.webkitAudioContext;
const audioCtx = new AudioContext();
// 创建振荡器
const oscillator = audioCtx.createOscillator();
const gainNode = audioCtx.createGain();
oscillator.connect(gainNode);
gainNode.connect(audioCtx.destination);
// 设置音效参数
if (type === 'complete') {
oscillator.type = 'sine';
oscillator.frequency.setValueAtTime(523.25, audioCtx.currentTime); // C5
oscillator.frequency.setValueAtTime(659.25, audioCtx.currentTime + 0.1); // E5
oscillator.frequency.setValueAtTime(783.99, audioCtx.currentTime + 0.2); // G5
gainNode.gain.setValueAtTime(0.1, audioCtx.currentTime);
gainNode.gain.exponentialRampToValueAtTime(0.01, audioCtx.currentTime + 0.3);
oscillator.start(audioCtx.currentTime);
oscillator.stop(audioCtx.currentTime + 0.3);
}
} catch (error) {
console.error('播放音效失败:', error);
// 音效播放失败不影响主要功能
}
}
// 重新测试函数
function handleRetest() {
try {
// 清除本地存储结果
localStorage.removeItem('pigTestResult');
// 重置进度条
resetProgress();
// 显示测试区域,隐藏结果区域
testArea.classList.remove('hidden');
resultArea.classList.add('hidden');
// 重置提示文字
instruction.textContent = '长按屏幕中间区域,看看你是什么猪!';
} catch (error) {
console.error('重新测试失败:', error);
}
}
// 触摸事件监听
try {
const progressContainer = document.querySelector('.progress-container');
if (progressContainer) {
progressContainer.addEventListener('mousedown', handleHoldStart);
progressContainer.addEventListener('touchstart', handleHoldStart);
}
document.addEventListener('mouseup', handleHoldEnd);
document.addEventListener('touchend', handleHoldEnd);
document.addEventListener('touchcancel', handleHoldEnd);
// 重新测试按钮事件监听
retestButton.addEventListener('click', handleRetest);
} catch (error) {
console.error('添加事件监听失败:', error);
}
</script>
</body>
</html>