Laravel  
laravel
文档
数据库
架构
入门
php技术
    
Laravelphp
laravel / php / java / vue / mysql / linux / python / javascript / html / css / c++ / c#

html动画

作者:尛丸子的天真▍我学不会゜   发布日期:2025-09-18   浏览:87

<!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>

解释说明:

  1. @keyframes:定义了一个名为 example 的关键帧动画,它描述了元素在不同时间点的状态变化。

    • 0%100% 表示动画从开始到结束的不同状态。
    • 在每个百分比位置,设置了不同的背景颜色和位置变化。
  2. #animate:选择器应用于一个 div 元素,设置了宽度、高度、位置和初始背景颜色,并应用了前面定义的动画。

    • animation-name 指定了要使用的动画名称。
    • animation-duration 设置了动画的持续时间为 4 秒。
    • animation-iteration-count 设置为 infinite,表示动画会无限循环播放。

这个示例展示了如何使用 CSS 动画来创建一个简单的颜色和位置变化的动画效果。

上一篇:html网页设计源代码

下一篇:div在html是什么意思

大家都在看

静态html源码

404 html

ios打开html

colspan在html中是什么意思

xml转html

html时间代码

html2canvas使用

html标题标签是什么

html 换行符号

html中b标签的作用

Laravel PHP 深圳智简公司。版权所有©2023-2043 LaravelPHP 粤ICP备2021048745号-3

Laravel 中文站