feat: add shake effect

This commit is contained in:
2023-12-13 00:15:41 +08:00
parent 520e9febd0
commit a886b4d3f2
2 changed files with 30 additions and 1 deletions

View File

@@ -74,6 +74,7 @@ function handleClick(dishName) {
} else {
// 错误答案的处理逻辑
console.log("不幸,这不是正确答案。");
addShakeEffect()
failedTimes = failedTimes + 1;
switch (failedTimes) {
case 1:
@@ -171,3 +172,17 @@ document.addEventListener("DOMContentLoaded", function() {
document.getElementById("dialogueText").innerHTML = randomQuestion;
console.log(answers[QAlist[currentIndex]]);
});
// 为所有元素添加抖动效果
function addShakeEffect() {
const allElements = document.querySelectorAll('body *'); // 选择页面上的所有元素
allElements.forEach(el => {
el.classList.add('shake-animation');
});
// 设置定时器以在动画完成后移除抖动效果
setTimeout(() => {
allElements.forEach(el => {
el.classList.remove('shake-animation');
});
}, 800); // 与 CSS 动画时间相同
}