环境:vue2
功能:CSS样式添加阴影的时候让阴影部分保持动态闪烁效果
方案:运用animation动画 实现闪烁,keyframe 选择器更改阴影的颜色
效果:动态闪烁
样式书写:
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
|
li{ width: 120px; height: 35px; line-height: 35px; color: #fff; margin-bottom: 10px; animation: shadow 1.5s ease- in -out infinite; //重点 } @keyframes shadow { 0% { box-shadow: 0px 0px 4px 4px #ac03e900; } 25% { box-shadow: 0px 0px 4px 4px #ac03e970; } 50% { box-shadow: 0px 0px 4px 4px #ac03e9ab; } 75% { box-shadow: 0px 0px 4px 4px #ac03e970; } 100% { box-shadow: 0px 0px 4px 4px #cc90e293; } } |
示例:
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
|
<template> <div class = "about" > <h1>This is an about page</h1> <ul> <li>芹菜是一根葱1</li> <li>芹菜是一根葱2</li> <li>芹菜是一根葱3</li> <li>芹菜是一根葱4</li> <li>芹菜是一根葱5</li> </ul> </div> </template> <script> export default { name: 'HomeView' , } </script> <style lang= "less" scoped> ul,li{ list-style-type: none; //取消默认样式 margin: 0 auto; } li{ width: 120px; height: 35px; line-height: 35px; color: #fff; margin-bottom: 10px; animation: shadow 1.5s ease- in -out infinite; } @keyframes shadow { 0% { box-shadow: 0px 0px 4px 4px #ac03e900; } 25% { box-shadow: 0px 0px 4px 4px #ac03e970; } 50% { box-shadow: 0px 0px 4px 4px #ac03e9ab; } 75% { box-shadow: 0px 0px 4px 4px #ac03e970; } 100% { box-shadow: 0px 0px 4px 4px #cc90e293; } } </style> |