-
Notifications
You must be signed in to change notification settings - Fork 97
Expand file tree
/
Copy pathscript.js
More file actions
78 lines (63 loc) · 2.5 KB
/
script.js
File metadata and controls
78 lines (63 loc) · 2.5 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
let yesButton = document.getElementById("yes");
let noButton = document.getElementById("no");
let questionText = document.getElementById("question");
let mainImage = document.getElementById("mainImage");
const params = new URLSearchParams(window.location.search);
let username = params.get("name");
// 限制用户名长度,避免页面样式崩坏
const maxLength = 20;
const safeUsername = username ? username.substring(0, maxLength) : "???";
// 防止 `null` 变成 `"null"`
if (username) {
questionText.innerText = questionText.innerText + safeUsername;
}
let clickCount = 0; // 记录点击 No 的次数
// No 按钮的文字变化
const noTexts = [
"?你认真的吗…",
"要不再想想?",
"不许选这个! ",
"我会很伤心…",
"不行:(",
];
// No 按钮点击事件
noButton.addEventListener("click", function () {
clickCount++;
// 让 Yes 变大,每次放大 2 倍
let yesSize = 1 + clickCount * 1.2;
yesButton.style.transform = `scale(${yesSize})`;
// 挤压 No 按钮,每次右移 50px
let noOffset = clickCount * 50;
noButton.style.transform = `translateX(${noOffset}px)`;
// 让图片和文字往上移动
let moveUp = clickCount * 25;
mainImage.style.transform = `translateY(-${moveUp}px)`;
questionText.style.transform = `translateY(-${moveUp}px)`;
// No 文案变化(前 5 次变化)
if (clickCount <= 5) {
noButton.innerText = noTexts[clickCount - 1];
}
// 图片变化(前 5 次变化)
if (clickCount === 1) mainImage.src = "images/shocked.png"; // 震惊
if (clickCount === 2) mainImage.src = "images/think.png"; // 思考
if (clickCount === 3) mainImage.src = "images/angry.png"; // 生气
if (clickCount === 4) mainImage.src = "images/crying.png"; // 哭
if (clickCount >= 5) mainImage.src = "images/crying.png"; // 之后一直是哭
});
// Yes 按钮点击后,进入表白成功页面
const loveTest = `!!!喜欢你!! ( >᎑<)♡︎ᐝ ${
username ? `${safeUsername} ♡︎ᐝ(>᎑< )` : ""
}`;
yesButton.addEventListener("click", function () {
// 先创建基础 HTML 结构
document.body.innerHTML = `
<div class="yes-screen">
<h1 class="yes-text"></h1>
<img src="images/hug.png" alt="拥抱" class="yes-image">
</div>
`;
// 确保用户名安全地插入
document.querySelector(".yes-text").innerText = loveTest;
// 禁止滚动,保持页面美观
document.body.style.overflow = "hidden";
});