animation动画(2)

修改关键帧速率制作弹性小球

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
79
80
81
82
83
84
85
86
87
88
89
90
91
<!DOCTYPE html>
<html lang="en">

<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<link href="//netdna.bootstrapcdn.com/font-awesome/4.5.0/css/font-awesome.min.css" rel="stylesheet">
<style>
* {
margin: 0;
padding: 0;
}

main {
height: 100vh;
width: 100vw;
background-color: #34495e;
display: grid;
grid-template: 1fr/1fr;
}

ul {
display: grid;
grid-template: 1fr/repeat(5, 1fr);
list-style: none;
}

div {
display: grid;
width: 50px;
height: 50px;
background-color: #d35400;
border-radius: 50%;
grid-column: 3/4;
justify-self: center;
animation-name: move;
animation-duration: 2s;
animation-iteration-count: 1;
animation-fill-mode: forwards;
}

@keyframes move {
0% {
transform: translateY(0vh);
transition-timing-function: ease-in;
}

30% {
transform: translateY(10vh);
transition-timing-function: ease-in;
}

60% {
transform: translateY(40vh);
transition-timing-function: ease-in;
}

80% {
transform: translateY(60vh);
transition-timing-function: ease-in;
}

95% {
transform: translateY(60vh);
transition-timing-function: ease-in;
}

15%,
45%,
75%,
85%,
100% {
transform: translateY(90vh);
transition-timing-function: ease-out;
}
}
</style>
</head>

<body>
<main>
<ul>
<div></div>
</ul>

</main>
</body>

</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
66
67
68
69
70
71
<!DOCTYPE html>
<html lang="en">

<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<link href="//netdna.bootstrapcdn.com/font-awesome/4.5.0/css/font-awesome.min.css" rel="stylesheet">
<style>
* {
margin: 0;
padding: 0;
}

main {
height: 100vh;
width: 100vw;
display: grid;
grid-template: 1fr/1fr;
}

button {
align-self: center;
justify-self: center;
width: 200px;
height: 50px;
background: #ecf0f1;
color: #180710;
border: solid 1px #ddd;


}

button::after {
content: '';
width: 3px;
height: 3px;
display: inline-block;
animation-name: hd;
animation-duration: 1s;
animation-iteration-count: infinite;
}

@keyframes hd {
0% {
box-shadow: none;
}

30% {
box-shadow: 3px 0 0 currentColor;
}

60% {
box-shadow: 3px 0 0 currentColor, 9px 0 0 currentColor;
}

90% {
box-shadow: 3px 0 0 currentColor, 9px 0 0 currentColor, 15px 0 0 currentColor;
}
}
</style>
</head>

<body>
<main>
<button>提交</button>
</main>
</body>

</html>

steps步进动画

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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
<!DOCTYPE html>
<html lang="en">

<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<link href="//netdna.bootstrapcdn.com/font-awesome/4.5.0/css/font-awesome.min.css" rel="stylesheet">
<style>
* {
margin: 0;
padding: 0;
}

body {
width: 100vw;
height: 100vh;
background: #34495e;
display: grid;
}

main {
display: grid;
width: 400px;
height: 200px;
align-self: center;
justify-self: center;
grid-template: repeat(2, 1fr)/repeat(4, 1fr);
}

div {
text-align: center;
background: #f1c40f;
border: solid 1px #2c3e50;
box-sizing: border-box;
position: relative;
}

div:nth-child(1)::before,
div:nth-child(5)::before {
animation-name: hd;
animation-duration: 2s;
animation-iteration-count: infinite;
z-index: 2;
}

div:nth-child(1)::before {
content: "START";
width: 100px;
height: 100px;
background-color: #8e44ad;
position: absolute;
left: 0;
top: 0;
animation-timing-function: steps(4, start);
/*马上运动*/
}

div:nth-child(5)::before {
content: "END";
width: 100px;
height: 100px;
background-color: #27ae60;
position: absolute;
left: 0;
top: 0;
animation-timing-function: steps(4, end);
/*等一会才动*/
}

@keyframes hd {
to {
transform: translateX(400px);
}
}
</style>
</head>

<body>
<main>
<div>1</div>
<div>2</div>
<div>3</div>
<div>4</div>
<div>5</div>
<div>6</div>
<div>7</div>
<div>8</div>
</main>
</body>

</html>

控制动画播放与暂停

1
animation-play-start:running|paused

填充模式

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
79
80
81
82
83
84
85
86
87
88
89
90
91
<!DOCTYPE html>
<html lang="en">

<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<link href="//netdna.bootstrapcdn.com/font-awesome/4.5.0/css/font-awesome.min.css" rel="stylesheet">
<style>
* {
margin: 0;
padding: 0;
}

body {
width: 100vw;
height: 100vh;
background: #34495e;
display: grid;
}

ul {
width: 400px;
height: 100px;
display: grid;
grid-template: 1fr/repeat(4, 1fr);
align-self: center;
justify-self: center;
list-style: none;
}

li {
width: 100px;
height: 100px;
background-color: #e67e22;
border-radius: 50%;
animation-duration: 2s;
display: grid;
animation-delay: 2s;
justify-items: center;
align-items: center;
}

li:nth-child(1) {
animation-name: hd;
/* normal 从初始状态到100%再回到初始状态 */
}

li:nth-child(2) {
animation-name: hd;
animation-fill-mode: forwards;
/* 起始状态到结束帧 */
}

li:nth-child(3) {
animation-name: hd;
animation-fill-mode: backwards;
/* 延迟时使用第一帧 */

}

li:nth-child(4) {
animation-name: hd;
animation-fill-mode: both;
/* 起始的时候是0帧,结束的时候是100帧 */
}

@keyframes hd {
from {
transform: scale(0);
}

to {
transform: scale(1);
background: #27ae60;
}
}
</style>
</head>

<body>
<ul>
<li>normal</li>
<li>forwards</li>
<li>backwards</li>
<li>both</li>
</ul>
</body>

</html>

组合定义语法

1
2
animation: name duration timing-function delay iteration-count direction fill-mode;
duration必须要有

animation动画(2)
https://blog-theta-ten.vercel.app/2021/07/26/animation动画-2/
作者
Chen
发布于
2021年7月26日
许可协议