<分区>
标签 jquery html css animate.css
<分区>
$(document).ready(function() {
$(".test").click(function() {
$(".test").addClass("animated shake");
});
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/animate.css/3.5.2/animate.min.css" />
<span class="test">element</span>
我哪里出错了?从现在开始感谢您的帮助...
最佳答案
因为 span
是内联元素,所以 transform
和其他属性将不起作用...
...所以尝试将 display:inline-block
添加到 span
...同样在您的 jQuery 代码中使用 $(this).addClass("animated shake")
而不是 $(".test").addClass("animated shake")
。
$(this).addClass("animated shake")
... 它将向点击的 .test
元素添加类。
$(".test").addClass("animated shake")
... 它将向所有 .test
元素添加类。
堆栈片段
$(document).ready(function() {
$(".test").click(function() {
$(this).addClass("animated shake");
});
});
.test {
display: inline-block;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/animate.css/3.5.2/animate.min.css" />
<span class="test">element</span>
关于jquery addclass 不适用于 animate.css,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48961245/