CSS box-shadow 动画

偶然看到效果不错使用 box-shadowcss 动画。
点此在 [新页面预览]

效果预览

代码

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
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
<!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>Shadow</title>
<style>
.box {
top: 50%;
left: 50%;
width: 200px;
height: 200px;
position: relative;
position: absolute;
margin-top: -100px;
margin-left: -100px;
}

.box:after,
.box:before {
content: "";
border-radius: 66%;
position: absolute;
top: 0;
left: 0;
width: 100%;
height: 100%;
-webkit-transform-origin: center center;
-ms-transform-origin: center center;
transform-origin: center center;
}

.box:after {
box-shadow: inset 0 23.33333333px 0 rgba(250, 250, 0, 0.6),
inset 23.33333333px 0 0 rgba(250, 200, 0, 0.6),
inset 0 -23.33333333px 0 rgba(250, 150, 0, 0.6),
inset -23.33333333px 0 0 rgba(250, 100, 0, 0.6);
-webkit-animation: rotar 2s -0.5s linear infinite;
animation: rotar 2s -0.5s linear infinite;
}

.box:before {
box-shadow: inset 0 23.33333333px 0 rgba(0, 250, 250, 0.6),
inset 23.33333333px 0 0 rgba(0, 200, 200, 0.6),
inset 0 -23.33333333px 0 rgba(0, 150, 200, 0.6),
inset -23.33333333px 0 0 rgba(0, 200, 250, 0.6);
-webkit-animation: rotarIz 2s -0.5s linear infinite;
animation: rotarIz 2s -0.5s linear infinite;
}

@-webkit-keyframes rotar {
0% {
-webkit-transform: rotateZ(0deg) scaleX(1) scaleY(1);
transform: rotateZ(0deg) scaleX(1) scaleY(1);
}

50% {
-webkit-transform: rotateZ(180deg) scaleX(0.82) scaleY(0.95);
transform: rotateZ(180deg) scaleX(0.82) scaleY(0.95);
}

100% {
-webkit-transform: rotateZ(360deg) scaleX(1) scaleY(1);
transform: rotateZ(360deg) scaleX(1) scaleY(1);
}
}

@keyframes rotar {
0% {
-webkit-transform: rotateZ(0deg) scaleX(1) scaleY(1);
transform: rotateZ(0deg) scaleX(1) scaleY(1);
}

50% {
-webkit-transform: rotateZ(180deg) scaleX(0.82) scaleY(0.95);
transform: rotateZ(180deg) scaleX(0.82) scaleY(0.95);
}

100% {
-webkit-transform: rotateZ(360deg) scaleX(1) scaleY(1);
transform: rotateZ(360deg) scaleX(1) scaleY(1);
}
}

@-webkit-keyframes rotarIz {
0% {
-webkit-transform: rotateZ(0deg) scaleX(1) scaleY(1);
transform: rotateZ(0deg) scaleX(1) scaleY(1);
}

50% {
-webkit-transform: rotateZ(-180deg) scaleX(0.95) scaleY(0.85);
transform: rotateZ(-180deg) scaleX(0.95) scaleY(0.85);
}

100% {
-webkit-transform: rotateZ(-360deg) scaleX(1) scaleY(1);
transform: rotateZ(-360deg) scaleX(1) scaleY(1);
}
}

@keyframes rotarIz {
0% {
-webkit-transform: rotateZ(0deg) scaleX(1) scaleY(1);
transform: rotateZ(0deg) scaleX(1) scaleY(1);
}

50% {
-webkit-transform: rotateZ(-180deg) scaleX(0.95) scaleY(0.85);
transform: rotateZ(-180deg) scaleX(0.95) scaleY(0.85);
}

100% {
-webkit-transform: rotateZ(-360deg) scaleX(1) scaleY(1);
transform: rotateZ(-360deg) scaleX(1) scaleY(1);
}
}
</style>
</head>

<body>
<div class="box">
</div>
</body>

</html>

CSS box-shadow 动画
https://tedding.dev/2023/06/28/189009e1b48.html
作者
TED.DING
发布于
2023年6月28日
许可协议