首页 技术 正文
技术 2022年11月7日
0 收藏 730 点赞 976 浏览 2925 个字

说在前面

描述 [加载中loading…] 的动画图片往往使用GIF来实现,但GIF消耗资源较大,所以使用CSS直接制作更优。

效果传送门1  效果传送门2


关键代码

@keyframes 规则  用于设定动画规则  <文档传送门>

animation 属性    用于设定动画    <文档传送门>

transform 属性    用于设定旋转角度  <文档传送门>


正文

效果1的实现

</>部分:(只有一个div)

<div class='dash-ring'></div>

CSS部分:

.dash-ring{
width:10px;
height:10px;
margin:0 auto;                    /*居中*/
padding:10px;
border:5px dashed #666;
border-radius: 50%;                 /*设定圆角边框,50%即以当前元素宽度的一半为半径,画1/4圆,4个角拼起来就是一个圆*/
animation: dash-ring-loading 1.5s infinite;   /*设定动画*/
animation-timing-function: linear;        /*设定动画函数为线性(默认是ease,效果不同)*/
}
@keyframes dash-ring-loading{                /*定义一个名为dash-ring-loading的动画*/
50% {                          /*动画时长的百分比(参数范围:0%~100%),其中0%可用from代替,100%可用to代替。*/
transform: rotate(180deg);           /*50%表示运行到一半,transform转至180度即可*/
}
100% {
transform: rotate(360deg);          /*100%表示运行结束,转至360度回到原点*/
}
}

效果2的实现

</>部分:

<div class="m-load"></div><div class="m-load2">
<div class="line">
<div></div>
<div></div>
<div></div>
<div></div>
<div></div>
<div></div>
</div>
<div class="circlebg"></div>
</div>

CSS部分:

*{margin:;padding:;}
body{background:#000;}.m-load,.m-load2{width:36px;height:36px;margin:100px auto;}
.m-load{background:url('load-v1.gif') #000 center center no-repeat;}
.m-load2{background:#000;}/** 加载动画的静态样式 **/
.m-load2{position:relative;}
.m-load2 .line div{position:absolute;left:16px;top:;width:3px;height:36px;}
.m-load2 .line div:before,.m-load2 .line div:after{content:'';display:block;height:50%;background:#fcfcfc;border-radius:5px;}
.m-load2 .line div:nth-child(2){-webkit-transform:rotate(30deg);}
.m-load2 .line div:nth-child(3){-webkit-transform:rotate(60deg);}
.m-load2 .line div:nth-child(4){-webkit-transform:rotate(90deg);}
.m-load2 .line div:nth-child(5){-webkit-transform:rotate(120deg);}
.m-load2 .line div:nth-child(6){-webkit-transform:rotate(150deg);}
.m-load2 .circlebg{position:absolute;left:50%;top:50%;width:18px;height:18px;margin:-9px 0 0 -9px;background:#000;border-radius:18px;}/** 加载动画 **/
@keyframes load{
0%{opacity:;}
100%{opacity:;}
}
.m-load2 .line div:nth-child(1):before{-webkit-animation:load 1.2s linear 0s infinite;}
.m-load2 .line div:nth-child(2):before{-webkit-animation:load 1.2s linear 0.1s infinite;}
.m-load2 .line div:nth-child(3):before{-webkit-animation:load 1.2s linear 0.2s infinite;}
.m-load2 .line div:nth-child(4):before{-webkit-animation:load 1.2s linear 0.3s infinite;}
.m-load2 .line div:nth-child(5):before{-webkit-animation:load 1.2s linear 0.4s infinite;}
.m-load2 .line div:nth-child(6):before{-webkit-animation:load 1.2s linear 0.5s infinite;}
.m-load2 .line div:nth-child(1):after{-webkit-animation:load 1.2s linear 0.6s infinite;}
.m-load2 .line div:nth-child(2):after{-webkit-animation:load 1.2s linear 0.7s infinite;}
.m-load2 .line div:nth-child(3):after{-webkit-animation:load 1.2s linear 0.8s infinite;}
.m-load2 .line div:nth-child(4):after{-webkit-animation:load 1.2s linear 0.9s infinite;}
.m-load2 .line div:nth-child(5):after{-webkit-animation:load 1.2s linear 1s infinite;}
.m-load2 .line div:nth-child(6):after{-webkit-animation:load 1.2s linear 1.1s infinite;}
相关推荐
python开发_常用的python模块及安装方法
adodb:我们领导推荐的数据库连接组件bsddb3:BerkeleyDB的连接组件Cheetah-1.0:我比较喜欢这个版本的cheeta…
日期:2022-11-24 点赞:878 阅读:9,090
Educational Codeforces Round 11 C. Hard Process 二分
C. Hard Process题目连接:http://www.codeforces.com/contest/660/problem/CDes…
日期:2022-11-24 点赞:807 阅读:5,567
下载Ubuntn 17.04 内核源代码
zengkefu@server1:/usr/src$ uname -aLinux server1 4.10.0-19-generic #21…
日期:2022-11-24 点赞:569 阅读:6,415
可用Active Desktop Calendar V7.86 注册码序列号
可用Active Desktop Calendar V7.86 注册码序列号Name: www.greendown.cn Code: &nb…
日期:2022-11-24 点赞:733 阅读:6,187
Android调用系统相机、自定义相机、处理大图片
Android调用系统相机和自定义相机实例本博文主要是介绍了android上使用相机进行拍照并显示的两种方式,并且由于涉及到要把拍到的照片显…
日期:2022-11-24 点赞:512 阅读:7,824
Struts的使用
一、Struts2的获取  Struts的官方网站为:http://struts.apache.org/  下载完Struts2的jar包,…
日期:2022-11-24 点赞:671 阅读:4,907