首先要知道什么是CSS3动画?然后才能做出自己想要的动画效果。下面会通过3个简单的Loading动画效果来对CSS3 animation动画做一个简单介绍,希望对你有用。

动画是使元素从一种样式逐渐变化为另一种样式的效果。 您可以改变任意多的样式任意多的次数。 使用百分比来规定变化发生的时间,或用关键词 "from" 和 "to",等同于 0% 和 100%。 0% 是动画的开始,100% 是动画的完成。

要创建CSS3动画,那么首先就要了解@keyframes规则。@keyframes规则是创建动画。 @keyframes规则内指定一个CSS样式和动画将逐步从目前的样式更改为新的样式。 当在 @keyframes 创建动画,把它绑定到一个选择器,否则动画不会有任何效果。 指定至少这两个CSS3的动画属性绑定向一个选择器:规定动画的名称;规定动画的时长。

Loading动画1:

     <div class="point-loading"><span class="point"></span><span class="point"></span><span class="point"></span><span class="point"></span><span class="point"></span><span class="point"></span><span class="point"></span><span class="point"></span></div><!-- html代码 总共8个点 -->/*css样式代码*/
/*定义动画*/
@keyframes pointLoading {0% {transform: scale(1);opacity: 1;}100% {transform: scale(.3);opacity: 0.5;}
}
/*定义样式*/
.point-loading {width: 100px;height: 100px;position: relative;margin: 0 auto;margin-top: 150px;margin-bottom: 100px;
}
.point-loading .point {width: 20px;height: 20px;border-radius: 50%;background: lightgreen;position: absolute;animation-name:pointLoading;   /*绑定动画*/animation-duration:1s; /*绑定动画完成一个周期所用时间*/animation-iteration-count:infinite; /*动画播放次数  默认是1,infinite无限次播放*/
}
/*nth-child:选择器匹配属于其父元素的第 N 个子元素;animation-delay:动画延迟播放*/
.point-loading .point:nth-child(1) {left: 0;top: 50%;margin-top: -10px;animation-delay: 0.13s;
}
.point-loading .point:nth-child(2) {left: 14px;top: 14px;animation-delay: 0.26s;
}
.point-loading .point:nth-child(3) {left: 50%;top: 0;margin-left: -10px;animation-delay: 0.39s;
}
.point-loading .point:nth-child(4) {top: 14px;right: 14px;animation-delay: 0.52s;
}
.point-loading .point:nth-child(5) {right: 0;top: 50%;margin-top: -10px;animation-delay: 0.65s;
}
.point-loading .point:nth-child(6) {right: 14px;bottom: 14px;animation-delay: 0.78s;
}
.point-loading .point:nth-child(7) {bottom: 0;left: 50%;margin-left: -10px;animation-delay: 0.91s;
}
.point-loading .point:nth-child(8) {bottom: 14px;left: 14px;animation-delay: 1.04s;
}
复制代码

Loading动画2:

     <!-- html代码--><div class="loading"></div>/*css代码*/
/*首先是定义动画效果*/
@keyframes rotateLoading {from {transform:rotate(0deg);}100% {transform: rotate(360deg);}
}
/*定义基本样式,绑定动画,定义动画属性*/
.loading {margin: 50px auto;width: 100px;height: 100px;border-radius: 50%;border: 10px solid  rgba(0, 0, 0, 0.2);border-top-color: #000;position: relative;animation-name: rotateLoading;animation-timing-function: linear;animation-duration: 1.1s;animation-iteration-count: infinite;
}
复制代码

Loading动画3:

<!--html代码 共5个柱状 --><div class="pillar-loading"><span class="pillar"></span><span class="pillar"></span><span class="pillar"></span><span class="pillar"></span><span class="pillar"></span></div>/*css代码*/
@keyframes pillarLoading {0%,100% {background: lightgreen;}50% {transform: scaleY(1.75);background: lightblue;}
}.pillar-loading {margin: 150px auto;width: 60px;display: flex;justify-content: space-between;
}
.pillar-loading .pillar {width: 8px;height: 40px;border-radius: 4px;background: lightgreen;animation-name: pillarLoading;animation-iteration-count: infinite;animation-duration: 1s;animation-timing-function: ease;
}
.pillar-loading .pillar:nth-child(2){animation-delay: 0.2s;
}
.pillar-loading .pillar:nth-child(3){animation-delay: 0.4s;
}
.pillar-loading .pillar:nth-child(4){animation-delay: 0.6s;
}
.pillar-loading .pillar:nth-child(5){animation-delay: 0.8s;
}
复制代码

以上3个动画是Animation动画的简单示例。

下面再说一个动画必备属性 transform。

transform 本意是变形,变换之意,在 CSS 中使用该属性可对元素进行移动(translate)、旋转(rotate)、缩放(scale)、倾斜(skew)等效果。因其有着各种特效及优良的性能,所以成为动画的标配。

** 转换方法**

一个简单的小球动画,鼠标移到小球上或者空白框内,小球开始做动画,鼠标移出,动画停止。

     <!-- html代码 --><div class="box"><div class="circle"></div></div>/*CSS代码*/
.box {width: 600px;height: 200px;border: 1px solid #ccc;background: #fff;margin: 50px,auto
}
.circle {width: 50px;height: 50px;background: blue;border-radius: 50%;margin: 75px,0;transition: all 2s   /*2s完成*/
}
.box:hover .circle {background: red;transform: translate(550px,0)   /*沿x轴偏移550px*/
}
复制代码

再来一个稍微难一点的。

<!-- html代码 -->
<a href="https://y.qq.com/n/yqq/album/002JRl3m16wLPL.html" class="playlist-item"><div class="item-bd"><img class="item-img" src="https://user-gold-cdn.xitu.io/2018/8/31/1658e70c78f71b6c?w=300&h=300&f=jpeg&s=44005" alt=""><i class="icon-play"></i></div><div class="item-ft"><h3 class="item-tt">漂洋过海来看你 OST 原声辑</h3><p class="item-author">严艺丹</p></div></a>/*css样式代码*/
.playlist-item {display: block;margin-top: 100px;width: 300px;background: rgba(0, 0, 0, .6);
}
.playlist-item:hover {background: #31c27c;
}.playlist-item .item-bd {overflow: hidden;position: relative;
}
.playlist-item .item-img {width: 100%;transition:all 0.75s;
}
.playlist-item .icon-play {position: absolute;top: 50%;left: 50%;transform: translate(-50%, -50%) scale(.7);width: 70px;height: 70px;background: url(http://coding.imweb.io/img/p3/transition-cover_play.png) no-repeat;opacity: 0;
}
.playlist-item .item-bd:hover .item-img {transform:scale(1.1);
}
.playlist-item .item-bd:hover .icon-play {opacity: 0.8;transform: translate(-50%, -50%) scale(1);
}
.playlist-item .item-ft {color: #fff;padding: 15px 10px;text-align: center;
}
.playlist-item .item-tt {font-size: 16px;position: relative;display: inline-block;vertical-align: middle;
}
.playlist-item .item-tt::after {content: "...";width: 18px;height: 18px;font-size: 12px;color: #fff;border-radius: 50%;border: 2px solid #fff;position: absolute;right: -25px;top: 50%;transform: translate(0, -50%);line-height: 0.6;box-sizing: border-box;opacity: 0;transition:all 0.75s;
}
.playlist-item .item-author {color: #999;
}
.playlist-item:hover .item-author {color: #c1e9d5;
}
.playlist-item:hover .item-tt::after {opacity:1;
}
复制代码

本文转载自:www.jianshu.com/p/6f53cc7d8…

参考资料:CSS3 transform www.w3cplus.com/content/css…

转载于:https://juejin.im/post/5b88ce13f265da435a486a54

CSS学习--DIY Loading动画相关推荐

  1. html设置loading,几个纯CSS实现的loading动画

    或者是因为网页体积较大,又或者是由于使用vue一类的前端库,浏览者在打开网页时往往会出现一段时间的白屏,通常的做法是在网页未完成首屏渲染时,向用户展示一个loading动画,页面渲染好了后再隐藏loa ...

  2. CSS制作简单loading动画

    曾经以为,loading的制作需要一些比较高深的web动画技术,后来发现大多数loading都可以用"障眼法"做出来.比如一个旋转的圆圈,并不都是将gif图放进去,有些就是画个静止 ...

  3. CSS学习17之动画

    回顾 z-index 属性 z-index 属性设置元素的堆叠顺序.拥有更高堆叠顺序的元素总是会处于堆叠顺序较低的元素的前面. Z-index 可用于将在一个元素放置于另一元素之后. 动画 动画使元素 ...

  4. 回归前端学习第19天——CSS一些简易小动画

    写一些CSS得动画和效果⑧ 动画中的关键帧 实现水平横动效果 进入时有缩放效果,鼠标滑过也会有缩放效果 一个等待的loading动画 动画中的关键帧 实现图片在浏览器内自动四处游荡~ <div ...

  5. CSS3学习笔记之loading动画

    效果截图: HTML代码: <div class="divBox"><div class="loader"><div class= ...

  6. CSS 实战: Loading 动画

    CSS 实战: Loading 动画 文章目录 CSS 实战: Loading 动画 正文 1. html 结构 2. div 实现样式 3. svg 实现样式 4. 实现效果 其他资源 参考连接 完 ...

  7. CSS学习笔记 08、过渡与动画

    文章目录 前言 一.过渡 1.1.过渡的基本介绍(transition: transform 1s linear 0s;) 介绍transition及其属性 属性过渡生效demo(7个示例) 1.2. ...

  8. css实现加载中loading动画效果

    1 效果 2 实现原理 原理很简单: 1 设置100px宽高的div,再设置成圆形border-radius:50%: 2 设置border一定宽度和颜色,再设置border-left为同样宽度和另一 ...

  9. css纯加载动画,纯CSS实现loading动画加载效果

    原标题:纯CSS实现loading动画加载效果 loading动画图标的做法有很多.一般不想麻烦的人直接嵌入一张gif的动态图标即可实现!虽然该方法方便快捷,但是对网站的加载速度优化方面还不是最好,制 ...

最新文章

  1. stdarg.h(c标准库)
  2. 通过点击切换文本框内容的脚本示例
  3. 网管,请别随意关闭默认共享
  4. 一个wepy开发微信小程序时图片在真机上不显示的问题
  5. logback日志pattern_003、Spring Boot使用slf4j进行日志记录
  6. 聚合丁苯橡胶(SSBR)行业调研报告 - 市场现状分析与发展前景预测
  7. mybatis_Mapped Statements collection already contains value
  8. 编写一个完整的应用程序:从键盘上读入一句英文(只包含英文字母、空格、半角逗号和半角 句号,如:I will choose the presentation..先将该英文句子首字母大写再把句子逆序输出。
  9. python opencv Shi-Tomasi 角点检测和特征跟踪
  10. 高性能web 架构之 mysql 读写分离
  11. unity3d-unet小demo
  12. Service starting has been prevented by iaware or trustsbase sInfo ServiceInfo 解决方法
  13. 关于计算机合成图像的应用中,数字图像合成技术综述
  14. OpenCV实现简单的录屏功能
  15. 使用g++创建动态库和静态库及其相关探索
  16. 从零开始搭建智能客服
  17. 正交矩阵的定义及证明和性质
  18. 2022-08-09 mysql/stonedb-慢SQL-Q16分析
  19. 读书笔记:SAFNet
  20. 1555:计算双阶乘

热门文章

  1. SAP零售行业解决方案初阶 4 – 维护品类
  2. 技术非中立,语言非同质:机器翻译正被用于维护文化障碍
  3. SAP PM 初级系列4 - 定义功能位置的结构标识
  4. SAP PM IW33里查看维护订单相关的维护计划
  5. CCAI 2020 | 史元春:走出AI伦理困境「演讲回顾」
  6. 机器学习中的集成学习模型实战完整讲解
  7. 过拟合、欠拟合与正则化
  8. SAP 序列号里'主批次'与'库存批次'不同,如何修改?
  9. SAP WM Production Schedule Profile设置问题导致生产补货的TO单自动创建问题
  10. Tensorflow—CNN应用于MNIST数据集分类