代码
提交代码
<!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title>Animate</title> <style> /* 清除浏览器默认边距 */ * { padding: 0; margin: 0; } /* 这段代码是为了居中显示,不是重点,看不懂的话可以无视 */ body { height: 100vh; display: flex; align-items: center; justify-content: center; } /* 先定义动画,动画名叫:change-color */ @keyframes change-color { from { color: red } 14% { color: orange } 28% { color: yellow } 42% { color: green } 56% { color: cyan } 70% { color: blue } 84% { color: purple } to { color: aquamarine } } .animate { width: 450px; height: 100px; /* 再使用预先定义好的动画 */ animation: change-color 7s step-end infinite; /* 动画:动画名(change-color) 时长(7秒) 动画运行的方式(step-end) 动画次数(无限) */ } </style> </head> <body> <div class="animate"> <!-- 动画:动画名(change-color) 时长(7秒) 动画运行的方式(step-end) 动画次数(无限)--> animation: change-color 7s step-end infinite; </div> </body> </html>
运行结果