<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>HTML 动画示例</title>
<style>
/* 定义关键帧动画 */
@keyframes example {
0% { background-color: red; left: 0px; top: 0px; }
25% { background-color: yellow; left: 200px; top: 0px; }
50% { background-color: blue; left: 200px; top: 200px; }
75% { background-color: green; left: 0px; top: 200px; }
100% { background-color: red; left: 0px; top: 0px; }
}
/* 应用动画到元素 */
#animate {
width: 100px;
height: 100px;
position: relative;
background-color: red;
animation-name: example;
animation-duration: 4s;
animation-iteration-count: infinite;
}
</style>
</head>
<body>
<div id="animate"></div>
</body>
</html>
@keyframes:定义了一个名为 example
的关键帧动画,它描述了元素在不同时间点的状态变化。
0%
到 100%
表示动画从开始到结束的不同状态。#animate:选择器应用于一个 div
元素,设置了宽度、高度、位置和初始背景颜色,并应用了前面定义的动画。
animation-name
指定了要使用的动画名称。animation-duration
设置了动画的持续时间为 4 秒。animation-iteration-count
设置为 infinite
,表示动画会无限循环播放。这个示例展示了如何使用 CSS 动画来创建一个简单的颜色和位置变化的动画效果。
上一篇:html网页设计源代码
下一篇:div在html是什么意思
Laravel PHP 深圳智简公司。版权所有©2023-2043 LaravelPHP 粤ICP备2021048745号-3
Laravel 中文站