当前位置:网站首页>充电效果模拟
充电效果模拟
2022-07-31 01:31:00 【盖玥希圈外男友(섭소우)】
目录
需求
继续摸鱼......
突发奇想,如何实现一个手机充电效果呢?类似于......emmm不太好找,所以省略了。总之就是,手机连接充电器后界面出现的动态效果。
思路分析与代码实现
这个显然也可以通过css动画实现。用一个圆圈显示当前电量,周围是一些颜色、形状都在变化的纯色区域。
实在不太好描述,直接上代码。
html部分
<div class="container clearfix">
<div class="fire">
<div class="fire-content"></div>
</div>
<div class="circle">
82.5%
</div>
</div>
css部分
.container {
width: 500px;
min-height: 600px;
background-color: black;
margin: 0 auto;
position: relative;
}
.circle {
width: 300px;
height: 300px;
border-radius: 50%;
margin: 100px auto;
border: 3px solid white;
color: white;
background-color: black;
line-height: 300px;
text-align: center;
font-size: 50px;
position: relative;
}
/* 清除外边距重叠 */
.clearfix::before,
.clearfix::after {
content: '';
display: table;
clear: both;
}
.fire {
width: 350px;
height: 320px;
position: absolute;
top: calc(50% - 50px);
left: 50%;
transform: translate(-50%, -50%);
}
.fire-content{
width: 100%;
height: 100%;
animation: rotate 10s infinite both reverse linear;
}
@keyframes rotate{
from{
transform: rotate(0);
background-color: azure;
border-radius: 260px 80px;
}
25%{
transform: rotate(90deg);
background-color: beige;
border-radius: 80px 260px;
}
50%{
transform: rotate(180deg);
background-color: bisque;
border-radius: 260px 80px;
}
75%{
transform: rotate(270deg);
background-color: powderblue;
border-radius: 80px 260px;
}
100%{
transform: rotate(360deg);
background-color: honeydew;
border-radius: 260px 80px;
}
}
这里需要注意,当transform和animation作用于同一个元素,并且animation也操作了transform时,可能会引起混乱。为此,可以在元素外面包一个父元素,transform操作父元素,animation操作子元素。这样分开,就不会混乱了。
所以,我用动画操作fire-content,而用transform操作fire。
实现效果
还挺像那么回事的嘛!
总结
这次代码比较简单,没有什么特别的,只有在应用动画和transform的时候需要注意的那一点。
发布的时候提示文章质量过低。。。。哎,低就低吧!
边栏推荐
猜你喜欢
typescript16-void
软件测试工作3年了,谈谈我是如何从刚入门进阶到自动化测试的?
【网络安全】文件上传靶场通关(1-11关)
Sping.事务的传播特性
What have I experienced when I won the offer of BAT and TMD technical experts?
Chi-square distribution of digital image steganography
C语言_结构体指针数组函数选票系统
Mysql:Invalid default value for TIMESTAMP
一万了解 Gateway 知识点
RTL8720DN开发笔记一 环境搭建与mqtt实例
随机推荐
权限管理怎么做的?
仿牛客网项目总结
网站频繁出现mysql等数据库连接失败等信息解决办法
使用PageHelper实现分页查询(详细)
使用docker安装mysql
查看zabbix-release-5.0-1.el8.noarch.rpm包内容
Basic Parameters of RF Devices 2
"Actual Combat" based on part-of-speech extraction in the field of e-commerce and its decision tree model modeling
有没有可以做副业可以日入300元方法?
typescript17 - function optional parameters
Can deep learning solve the parameters of a specific function?
typescript9 - common base types
pycharm重命名后无法运行(报错: can‘t open file......No such file or directory)
JS逆向之浏览器补环境(一)
Teach you how to configure Jenkins automated email notifications
TiDB之rawkv升级之路v5.0.4--&gt;v6.1.0
聚簇索引和非聚簇索引到底有什么区别
VS warning LNK4099: No solution found for PDB
ROS2系列知识(3):环境配置
SQLserver查询最近三个月的数据,语句该怎么写sqlserver