我用 CSS3 实现了一个超炫的 3D 加载动画
今天给大家带来一个非常炫酷的CSS3加载Loading动画,它的特别之处在于,整个Loading动画呈现出了3D的视觉效果。这个Loading加载动画由12个3D圆柱体围成一个椭圆形,同时这12个圆柱体依次波浪式地起伏,从而传递给用户“正在加载”的信息。
效果预览

代码实现
HTML代码
HTML代码十分简单,一共有三类对象,一个是最外面的椭圆容器,一个是12个圆柱体,最后是“Loading”文本。
<div class="pl">
<div class="pl__dot"></div>
<div class="pl__dot"></div>
<div class="pl__dot"></div>
<div class="pl__dot"></div>
<div class="pl__dot"></div>
<div class="pl__dot"></div>
<div class="pl__dot"></div>
<div class="pl__dot"></div>
<div class="pl__dot"></div>
<div class="pl__dot"></div>
<div class="pl__dot"></div>
<div class="pl__dot"></div>
<div class="pl__text">Loading…</div>
</div>
CSS代码
CSS代码主要做三件事情:
首先是让最外面的椭圆容器呈现出内陷的3D视觉效果,这里用带了box-shadow属性:
.pl {
box-shadow: 2em 0 2em rgba(0, 0, 0, 0.2) inset, -2em 0 2em rgba(255, 255, 255, 0.1) inset;
display: flex;
justify-content: center;
align-items: center;
position: relative;
letter-spacing: 0.1em;
text-transform: uppercase;
transform: rotateX(30deg) rotateZ(45deg);
width: 15em;
height: 15em;
}
然后是让12个<div>元素成为3D效果的小圆圈,这里主要用到了box-shadow和border-radius属性:
.pl__dot {
border-radius: 50%;
}
.pl__dot {
animation-name: shadow;
box-shadow: 0.1em 0.1em 0 0.1em black, 0.3em 0 0.3em rgba(0, 0, 0, 0.5);
top: calc(50% - 0.75em);
left: calc(50% - 0.75em);
width: 1.5em;
height: 1.5em;
}
.pl__dot, .pl__dot:before, .pl__dot:after {
animation-duration: 2s;
animation-iteration-count: infinite;
position: absolute;
}
.pl__dot:before, .pl__dot:after {
content: "";
display: block;
left: 0;
width: inherit;
transition: background-color var(--trans-dur);
}
.pl__dot:before {
animation-name: pushInOut1;
background-color: var(--bg);
border-radius: inherit;
box-shadow: 0.05em 0 0.1em rgba(255, 255, 255, 0.2) inset;
height: inherit;
z-index: 1;
}
.pl__dot:after {
animation-name: pushInOut2;
background-color: var(--primary1);
border-radius: 0.75em;
box-shadow: 0.1em 0.3em 0.2em rgba(255, 255, 255, 0.4) inset, 0 -0.4em 0.2em #2e3138 inset, 0 -1em 0.25em rgba(0, 0, 0, 0.3) inset;
bottom: 0;
clip-path: polygon(0 75%, 100% 75%, 100% 100%, 0 100%);
height: 3em;
transform: rotate(-45deg);
transform-origin: 50% 2.25em;
}
最后一步就是让12个小圆圈按不同是时间间隔旋转不同的角度,从而形成波浪式的起伏效果。
.pl__dot:nth-child(1) {
transform: rotate(0deg) translateX(5em) rotate(0deg);
z-index: 5;
}
.pl__dot:nth-child(1), .pl__dot:nth-child(1):before, .pl__dot:nth-child(1):after {
animation-delay: 0s;
}
.pl__dot:nth-child(2) {
transform: rotate(-30deg) translateX(5em) rotate(30deg);
z-index: 4;
}
.pl__dot:nth-child(2), .pl__dot:nth-child(2):before, .pl__dot:nth-child(2):after {
animation-delay: -0.1666666667s;
}
.pl__dot:nth-child(3) {
transform: rotate(-60deg) translateX(5em) rotate(60deg);
z-index: 3;
}
.pl__dot:nth-child(3), .pl__dot:nth-child(3):before, .pl__dot:nth-child(3):after {
animation-delay: -0.3333333333s;
}
.pl__dot:nth-child(4) {
transform: rotate(-90deg) translateX(5em) rotate(90deg);
z-index: 2;
}
.pl__dot:nth-child(4), .pl__dot:nth-child(4):before, .pl__dot:nth-child(4):after {
animation-delay: -0.5s;
}
.pl__dot:nth-child(5) {
transform: rotate(-120deg) translateX(5em) rotate(120deg);
z-index: 1;
}
.pl__dot:nth-child(5), .pl__dot:nth-child(5):before, .pl__dot:nth-child(5):after {
animation-delay: -0.6666666667s;
}
.pl__dot:nth-child(6) {
transform: rotate(-150deg) translateX(5em) rotate(150deg);
z-index: 1;
}
.pl__dot:nth-child(6), .pl__dot:nth-child(6):before, .pl__dot:nth-child(6):after {
animation-delay: -0.8333333333s;
}
.pl__dot:nth-child(7) {
transform: rotate(-180deg) translateX(5em) rotate(180deg);
z-index: 2;
}
.pl__dot:nth-child(7), .pl__dot:nth-child(7):before, .pl__dot:nth-child(7):after {
animation-delay: -1s;
}
.pl__dot:nth-child(8) {
transform: rotate(-210deg) translateX(5em) rotate(210deg);
z-index: 3;
}
.pl__dot:nth-child(8), .pl__dot:nth-child(8):before, .pl__dot:nth-child(8):after {
animation-delay: -1.1666666667s;
}
.pl__dot:nth-child(9) {
transform: rotate(-240deg) translateX(5em) rotate(240deg);
z-index: 4;
}
.pl__dot:nth-child(9), .pl__dot:nth-child(9):before, .pl__dot:nth-child(9):after {
animation-delay: -1.3333333333s;
}
.pl__dot:nth-child(10) {
transform: rotate(-270deg) translateX(5em) rotate(270deg);
z-index: 5;
}
.pl__dot:nth-child(10), .pl__dot:nth-child(10):before, .pl__dot:nth-child(10):after {
animation-delay: -1.5s;
}
.pl__dot:nth-child(11) {
transform: rotate(-300deg) translateX(5em) rotate(300deg);
z-index: 6;
}
.pl__dot:nth-child(11), .pl__dot:nth-child(11):before, .pl__dot:nth-child(11):after {
animation-delay: -1.6666666667s;
}
.pl__dot:nth-child(12) {
transform: rotate(-330deg) translateX(5em) rotate(330deg);
z-index: 6;
}
.pl__dot:nth-child(12), .pl__dot:nth-child(12):before, .pl__dot:nth-child(12):after {
animation-delay: -1.8333333333s;
}
另外,在12个小圆圈渐进式地变成小圆柱体的时候,圆柱体的阴影和高度变化运用到了下面的CSS3动画:
@keyframes shadow {
from {
animation-timing-function: ease-in;
box-shadow: 0.1em 0.1em 0 0.1em black, 0.3em 0 0.3em rgba(0, 0, 0, 0.3);
}
25% {
animation-timing-function: ease-out;
box-shadow: 0.1em 0.1em 0 0.1em black, 0.8em 0 0.8em rgba(0, 0, 0, 0.5);
}
50%, to {
box-shadow: 0.1em 0.1em 0 0.1em black, 0.3em 0 0.3em rgba(0, 0, 0, 0.3);
}
}
@keyframes pushInOut1 {
from {
animation-timing-function: ease-in;
background-color: var(--bg);
transform: translate(0, 0);
}
25% {
animation-timing-function: ease-out;
background-color: var(--primary2);
transform: translate(-71%, -71%);
}
50%, to {
background-color: var(--bg);
transform: translate(0, 0);
}
}
@keyframes pushInOut2 {
from {
animation-timing-function: ease-in;
background-color: var(--bg);
clip-path: polygon(0 75%, 100% 75%, 100% 100%, 0 100%);
}
25% {
animation-timing-function: ease-out;
background-color: var(--primary1);
clip-path: polygon(0 25%, 100% 25%, 100% 100%, 0 100%);
}
50%, to {
background-color: var(--bg);
clip-path: polygon(0 75%, 100% 75%, 100% 100%, 0 100%);
}
}
到这里,我们就完整地实现了这个纯CSS3 3D加载动画,文章最后也将源码献给大家。
源码下载
完整的代码我已经整理出了一个源码包,供大家下载学习。
关注我的公众号“前端技术官”,回复关键字:3006,即可获取源码下载链接。
代码仅供参考和学习,请不要用于商业用途。
最后总结
这个CSS3 3D Loading加载动画主要运用了CSS3的动画帧属性、box-shadow属性以及animation-delay属性,希望本文对你的开发有所帮助。
我用 CSS3 实现了一个超炫的 3D 加载动画的更多相关文章
- 一款由jquery实现的超炫的页面加载特效
今天为大家带来一款由jquery实现的超炫的页面加载特效.连续的几个页面分开特效.最后由三维的线条由远至近消失,然后由近至远出现.效果超级梦炫.一起看下效果图: 在线预览 源码下载 实现的代码. ...
- 基于css3炫酷页面加载动画特效代码
基于CSS3实现35个动画SVG图标.这是一款基于jQuery+CSS3实现的SVG图标动画代码.效果图如下: 在线预览 源码下载 实现的代码. html代码: <div class=&qu ...
- CSS3,JS可用于刷新按钮或者加载动画的动画
html: <input type="button" id="zidong3" style="top: 12px;" /> cs ...
- 5个基于css3超炫的鼠标滑动按钮动画
今天给大家分享5个基于css3超炫的鼠标滑动按钮动画.这5个按钮鼠标经过的时候有超炫的动画效果.这5个按钮适用浏览器:360.FireFox.Chrome.Safari.Opera.傲游.搜狗.世界之 ...
- 几行css3代码实现超炫加载动画
之前为大家分享了css3实现的加载动画.今天为大家带来一款只需几行代码就可以实现超炫的动画加载特效.我们一起看下效果图: 在线预览 源码下载 实现代码: 极简的html代码: <div> ...
- 为网格布局图片打造的超炫 CSS 加载动画
今天,我想与大家分享一些专门为网格布局的图像制作的很酷的 CSS 加载动画效果.您可以把这些效果用在你的作品集,博客或任何你想要的网页中.设置很简单.我们使用了下面这些工具库来实现这个效果: Norm ...
- 超酷jQuery进度条加载动画集合
在丰富多彩的网页世界中,进度条加载动画的形式非常多样,有利用gif图片实现的loading动画,也有利用jQuery和CSS3实现的进度加载动画,本文主要向大家介绍很多jQuery和CSS3实现的进度 ...
- 用css3制作旋转加载动画的几种方法
以WebKit为核心的浏览器,例如Safari和Chrome,对html5有着很好的支持,在移动平台中这两个浏览器对应的就是IOS和Android.最近在开发一个移动平台的web app,那么就有机会 ...
- 2款不同样式的CSS3 Loading加载动画 附源码
原文:2款不同样式的CSS3 Loading加载动画 附源码 我们经常看到的Loading加载很多都是转圈圈的那种,今天我们来换一种有创意的CSS3 Loading加载动画,一种是声波形状的动画,另一 ...
随机推荐
- 各种环境下反弹shell
0x00 NC命令详解 在介绍如何反弹shell之前,先了解相关知识要点. nc全称为netcat,所做的就是在两台电脑之间建立链接,并返回两个数据流 可运行在TCP或者UDP模式,添加参数 -u 则 ...
- zookeeper从小白到精通
目录 1.介绍 1.1概念 1.2特点 1.3主要的集群步骤 1.4数据结构 1.5应用场景 2.本地安装 2.1安装jdk 2.2下载安装 2.3配置文件修改 2.4启动服务端 2.5启动客户端 2 ...
- C++中的RAII介绍
摘要 RAII技术被认为是C++中管理资源的最佳方法,进一步引申,使用RAII技术也可以实现安全.简洁的状态管理,编写出优雅的异常安全的代码. 资源管理 RAII是C++的发明者Bjarne Stro ...
- Spring Data Jpa 更新操作
第一步,通过Repository对象把实体根据ID查询出来 第二部,往查出来的实体对象进行set各个字段 第三步,通过Repository接口的save方法进行保存 保存和更新方式(已知两种) 第一种 ...
- 服务端处理 Watcher 实现 ?
1.服务端接收 Watcher 并存储 接收到客户端请求,处理请求判断是否需要注册 Watcher,需要的话将数据节点 的节点路径和 ServerCnxn(ServerCnxn 代表一个客户端和服务端 ...
- memcached 如何实现冗余机制?
不实现!我们对这个问题感到很惊讶.Memcached 应该是应用的缓存层.它的设 计本身就不带有任何冗余机制.如果一个 memcached 节点失去了所有数据,您 应该可以从数据源(比如数据库)再次获 ...
- c语言代码规范
什么叫规范?在C语言中不遵守编译器的规定,编译器在编译时就会报错,这个规定叫作规则.但是有一种规定,它是一种人为的.约定成俗的,即使不按照那种规定也不会出错,这种规定就叫作规范.虽然我们不按照规范也不 ...
- 利用Matlab快速绘制栅格地图
代码演示 % 基于栅格地图的机器人路径规划算法 % 第1节:利用Matlab快速绘制栅格地图 clc clear close all %% 构建颜色MAP图 cmap = [1 1 1; ... % ...
- 语言算子&模糊推理
一.语言算子 语言算子分为三类: ①语气算子 ②模糊化算子 ③判定化算子 (1)语气算子 "集中化算子":--"很"."极"."非 ...
- 利用angular4和nodejs-express构建一个简单的网站(一)——构建前后端开发环境
学习了一段时间的angular4知识,结合以前自学的nodejs-express后端框架知识,做了一个利用angular4作为前端,node-express作为后端服务器的网站.这个网站的功能很简单, ...