-
Notifications
You must be signed in to change notification settings - Fork 0
/
0916-49-css-animate.html
65 lines (55 loc) · 1.58 KB
/
0916-49-css-animate.html
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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>css animate</title>
<link
rel="stylesheet"
href="https://cdnjs.cloudflare.com/ajax/libs/animate.css/4.1.1/animate.min.css"
/>
<style>
body {
margin: 50px;
}
.wrap {
width: 800px;
height: 400px;
background-color: #ccc;
margin: 10px;
padding: 20px;
position: relative;
}
.box {
width: 200px;
height: 200px;
padding: 20px 40px;
margin: 10px 20px;
background-color: #afa;
}
</style>
</head>
<body>
<div class="wrap">
<button>bounce</button>
<button>shakeX</button>
<div class="box animate__animated"></div>
</div>
<script src="https://code.jquery.com/jquery-3.5.1.js"
integrity="sha256-QWo7LDvxbWT2tbbQ97B53yJnYU3WhH/C8ycbRAkjPDc=" crossorigin="anonymous"></script>
<script>
// 寫死
// $("button").click(function () {
// $(".box").toggleClass('animate__bounce')
// })
$("button").click(function () {
let animate = 'animate__' + $(this).text();
// 執行一次後移除 class
// animationend,動畫結束的時候,removeClass
$(".box").addClass(animate).one('animationend', function () {
$(this).removeClass(animate);
});
});
</script>
</body>
</html>