CSS动画keyframes简单样例

一、代码部分

1.html

a 复制代码
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <link rel="stylesheet" href="style.css">
    <title>Document</title>
</head>
<body>
    <div class="circle1"></div>
    <div class="circle2"></div>
</body>
</html>

2.css

A 复制代码
.circle1{
    width: 180px;
    margin-top: 20px;
    background-color: green;
    height: 180px;
    border-radius: 50%;
    animation: test 4.0s ease-in-out infinite alternate;
    text-align: center;
}

@keyframes test {
    0%{transform: translate(100px,100px);}
    20%{transform: translate(200px,200px);}
    50%{transform: translate(300px,300px);}
    80%{transform: translate(400px,200px);}
    100%{transform: translate(500px,100px);}
}


.circle2{
    margin: 50px;
    width: 180px;
    height: 180px;
    background: blue;
    animation: sample 2s ease-in-out infinite alternate;
}


@keyframes sample {
    
    0%{background: pink; transform:scale(1) rotate(0deg); }

    20%{
        background-color: red;
        transform: scale(1.2) rotate(90deg);
    }
    40%{
        background-color: green;
        transform: scale(1.2) rotate(135deg);
    }
    60%{
        background-color: blue;
        transform: scale(1.2) rotate(180deg);
    }
    80%{
        background-color: saddlebrown;
        transform: scale(1.2) rotate(225deg);
    }
    100%{background: red; transform:scale(1.2) rotate(270deg);}
}

二、网页效果


三、说明

以上代码实现了一个简单的移动的圆形,一个旋转变色的矩形。

后续可以用录屏软件,录屏后转为gif动图。

相关推荐
七灵微1 小时前
【后端】单点登录
服务器·前端
持久的棒棒君5 小时前
npm安装electron下载太慢,导致报错
前端·electron·npm
crary,记忆7 小时前
Angular微前端架构:Module Federation + ngx-build-plus (Webpack)
前端·webpack·angular·angular.js
漂流瓶jz7 小时前
让数据"流动"起来!Node.js实现流式渲染/流式传输与背后的HTTP原理
前端·javascript·node.js
SamHou08 小时前
手把手 CSS 盒子模型——从零开始的奶奶级 Web 开发教程2
前端·css·web
我不吃饼干8 小时前
从 Vue3 源码中了解你所不知道的 never
前端·typescript
开航母的李大8 小时前
【中间件】Web服务、消息队列、缓存与微服务治理:Nginx、Kafka、Redis、Nacos 详解
前端·redis·nginx·缓存·微服务·kafka
Bruk.Liu8 小时前
《Minio 分片上传实现(基于Spring Boot)》
前端·spring boot·minio
鱼樱前端9 小时前
Vue3+d3-cloud+d3-scale+d3-scale-chromatic实现词云组件
前端·javascript·vue.js
zhangxingchao9 小时前
Flutter入门:Flutter开发必备Dart基础
前端