# 弹性过度
一切的过度皆应该由动画来完成
鸿蒙开机动画demo
复制代码
animation
方案
<style scoped>
main {
width: 100%; height: 229px;
display: flex;
}
label {
margin: auto;
}
input {
display: block;
width: 229px;
padding: .8em;
outline: none;
border: 1px solid #e3e3e3;
border-radius: 2px;
}
input:focus,
input:hover {
border-color: #b4a078;
}
input:not(:placeholder-shown) {
border-color: #be4141;
box-shadow: 0 0 0 2px rgba(255, 100, 97, 0.2);
}
input:not(:placeholder-shown) + .poptip {
color: #be4141;
}
input:valid {
border-color: #b4a078;
box-shadow: 0 0 0 2px rgba(180, 160, 120, 0.2);
}
input:valid + .poptip {
color: unset;
}
input:not(:focus) + .poptip {
transform: scale(0);
animation: elastic-dec .25s;
}
input:focus + .poptip {
transform: scale(1);
animation: elastic-grow .45s;
}
.poptip {
display: inline-block;
width: 236px;
font-size: 13px;
padding: .6em;
background: #fafafa;
position: relative;
margin-left: -3px;
margin-top: 3px;
border-radius: 2px;
filter: drop-shadow(0 0 1px rgba(0, 0, 0, .23456));
transform-origin: 15px -6px;
}
.poptip::before {
content: "";
position: absolute;
top: -6px; left: 10px;
border: 9px solid transparent;
border-bottom-color: #fafafa;
border-top-width: 0;
}
@keyframes elastic-grow {
from {
transform: scale(0);
}
70% {
transform: scale(1.1);
animation-timing-function: cubic-bezier(.1, .25, .1, .25);
}
}
@keyframes elastic-dec {
from {
transform: scale(1);
}
to {
transform: scale(0);
animation-timing-function: cubic-bezier(.25, .1, .25, .1);
}
}
</style>
<template>
<main class="main">
<label>
<input
required
type="text"
id="username1"
autocomplete="off"
placeholder="请输入内容"
pattern="^\w+$"/>
<span class="poptip">仅支持字母、数字和下划线组合!!</span>
</label>
</main>
</template>
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
94
95
96
97
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
94
95
96
97
- 三次贝塞尔
cubic-bezier
+transition
方案
<style scoped>
main {
width: 100%; height: 229px;
display: flex;
}
label {
margin: auto;
}
input {
display: block;
width: 229px;
padding: .8em;
outline: none;
border: 1px solid #e3e3e3;
border-radius: 2px;
}
input:focus,
input:hover {
border-color: #b4a078;
}
input:not(:placeholder-shown) {
border-color: #be4141;
box-shadow: 0 0 0 2px rgba(255, 100, 97, 0.2);
}
input:not(:placeholder-shown) + .poptip {
color: #be4141;
}
input:valid {
border-color: #b4a078;
box-shadow: 0 0 0 2px rgba(180, 160, 120, 0.2);
}
input:valid + .poptip {
color: unset;
}
input:not(:focus) + .poptip {
transform: scale(0);
transition: transform .25s cubic-bezier(.25, .1, .25, .1);
}
input:focus + .poptip {
transform: scale(1);
transition: transform .4s cubic-bezier(.29, .15, .5, 1.46);
}
.poptip {
display: inline-block;
width: 236px;
font-size: 13px;
padding: .6em;
background: #fafafa;
position: relative;
margin-left: -3px;
margin-top: 3px;
border-radius: 2px;
filter: drop-shadow(0 0 1px rgba(0, 0, 0, .23456));
transform-origin: 15px -6px;
}
.poptip::before {
content: "";
position: absolute;
top: -6px; left: 10px;
border: 9px solid transparent;
border-bottom-color: #fafafa;
border-top-width: 0;
}
</style>
<template>
<main class="main">
<label>
<input
required
type="text"
id="username2"
autocomplete="off"
placeholder="请输入内容"
pattern="^\w+$"/>
<span class="poptip">仅支持字母、数字和下划线组合!!</span>
</label>
</main>
</template>
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
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
三次贝塞尔曲线cubic-bezier
主要是为animation
生成速度曲线的函数,语法是cubic-bezier(<x1>, <y1>, <x2>, <y2>)
,更多请参考:图形化工具cubic-bezier (opens new window)