【发布时间】:2022-09-27 17:42:12
【问题描述】:
我想在 vue.js-application 中创建抖动效果。我找到了一个例子,我可以用它创建一个用JavaScript创建的抖动效果,但是在vue.js中不能使用eventListener-所以我不知道如何在vue.js中使用这段代码。
你知道如何在没有 eventListener 的情况下在 vue.js 中使用这个动画吗?
这是我要调整的代码:
<!DOCTYPE html>
<html lang=\"en\">
<head>
<meta charset=\"UTF-8\">
<meta name=\"viewport\" content=\"width=device-width, initial-scale=1.0\">
<meta http-equiv=\"X-UA-Compatible\" content=\"ie=edge\">
<link rel=\"stylesheet\" href=\"./main.css\">
<title>3d Vector Kata</title>
<style>
/* Standard syntax */
@keyframes shake {
10%, 90% {
transform: translate3d(-1px, 0, 0);
}
20%, 80% {
transform: translate3d(2px, 0, 0);
}
30%, 50%, 70% {
transform: translate3d(-4px, 0, 0);
}
40%, 60% {
transform: translate3d(4px, 0, 0);
}
}
.apply-shake {
animation: shake 0.82s cubic-bezier(.36,.07,.19,.97) both;
}
</style>
</head>
<body>
<form id=\"test-form\">
<input type=\"text\" id=\"test-input\">
<button type=\"submit\" id=\"submit-button\" onclick=\"shakeAnimation()\">Submit</button>
</form>
<script src=\"./index.js\"></script>
</body>
</html>
<script>
const input = document.querySelector(\"input#test-input\");
const submit = document.querySelector(\"button#submit-button\");
submit.addEventListener(\"click\", (e) => {
e.preventDefault();
if(input.value === \"\") {
submit.classList.add(\"apply-shake\");
}
});
submit.addEventListener(\"animationend\", (e) => {
submit.classList.remove(\"apply-shake\");
});
</script>
-
but the eventListener can\'t be used in vue.js为什么不呢?也许你做错了。你展示的代码和vuejs没有关系,你怎么知道不能做你想做的
标签: javascript html css vue.js event-listener