侯体宗的博客
  • 首页
  • Hyperf版
  • beego仿版
  • 人生(杂谈)
  • 技术
  • 关于我
  • 更多分类
    • 文件下载
    • 文字修仙
    • 中国象棋ai
    • 群聊
    • 九宫格抽奖
    • 拼图
    • 消消乐
    • 相册

CSS3动画之DIY Loading动画

前端  /  管理员 发布于 7年前   380

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

动画是使元素从一种样式逐渐变化为另一种样式的效果。

您可以改变任意多的样式任意多的次数。

使用百分比来规定变化发生的时间,或用关键词 "from" 和 "to",等同于 0% 和 100%。

0% 是动画的开始,100% 是动画的完成。

要创建CSS3动画,那么首先就要了解@keyframes规则。@keyframes规则是创建动画。 @keyframes规则内指定一个CSS样式和动画将逐步从目前的样式更改为新的样式。

当在 @keyframes 创建动画,把它绑定到一个选择器,否则动画不会有任何效果。

指定至少这两个CSS3的动画属性绑定向一个选择器:规定动画的名称;规定动画的时长。

css3动画属性

Loading动画1:

点.gif

<!-- html代码 总共8个点 --> <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>
/*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:

圆环.gif

 <!-- 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:

柱状.gif

<!--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)等效果。因其有着各种特效及优良的性能,所以成为动画的标配。

** 转换方法**

transform转换方法

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

小球动画

 <!-- html代码 --><div class="box">        <div class="circle"></div>    </div>
.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*/}

再来一个稍微难一点的。

transform动画

<!-- html代码 --><a href="https://y.qq.com/n/yqq/album/002JRl3m16wLPL.html" class="playlist-item">        <div class="item-bd"><img class="item-img" src="http://coding.imweb.io/img/p3/transition-hover.jpg" 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;}

以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持。


  • 上一条:
    盘点CSS Selectors Level4中新增的选择器
    下一条:
    css 单选按钮图标替换的方法
  • 昵称:

    邮箱:

    0条评论 (评论内容有缓存机制,请悉知!)
    最新最热
    • 分类目录
    • 人生(杂谈)
    • 技术
    • linux
    • Java
    • php
    • 框架(架构)
    • 前端
    • ThinkPHP
    • 数据库
    • 微信(小程序)
    • Laravel
    • Redis
    • Docker
    • Go
    • swoole
    • Windows
    • Python
    • 苹果(mac/ios)
    • 相关文章
    • 使用 Alpine.js 排序插件对元素进行排序(0个评论)
    • 在js中使用jszip + file-saver实现批量下载OSS文件功能示例(0个评论)
    • 在vue中实现父页面按钮显示子组件中的el-dialog效果(0个评论)
    • 使用mock-server实现模拟接口对接流程步骤(0个评论)
    • vue项目打包程序实现把项目打包成一个exe可执行程序(0个评论)
    • 近期文章
    • 智能合约Solidity学习CryptoZombie第三课:组建僵尸军队(高级Solidity理论)(0个评论)
    • 智能合约Solidity学习CryptoZombie第二课:让你的僵尸猎食(0个评论)
    • 智能合约Solidity学习CryptoZombie第一课:生成一只你的僵尸(0个评论)
    • 在go中实现一个常用的先进先出的缓存淘汰算法示例代码(0个评论)
    • 在go+gin中使用"github.com/skip2/go-qrcode"实现url转二维码功能(0个评论)
    • 在go语言中使用api.geonames.org接口实现根据国际邮政编码获取地址信息功能(1个评论)
    • 在go语言中使用github.com/signintech/gopdf实现生成pdf分页文件功能(0个评论)
    • gmail发邮件报错:534 5.7.9 Application-specific password required...解决方案(0个评论)
    • 欧盟关于强迫劳动的规定的官方举报渠道及官方举报网站(0个评论)
    • 在go语言中使用github.com/signintech/gopdf实现生成pdf文件功能(0个评论)
    • 近期评论
    • 122 在

      学历:一种延缓就业设计,生活需求下的权衡之选中评论 工作几年后,报名考研了,到现在还没认真学习备考,迷茫中。作为一名北漂互联网打工人..
    • 123 在

      Clash for Windows作者删库跑路了,github已404中评论 按理说只要你在国内,所有的流量进出都在监控范围内,不管你怎么隐藏也没用,想搞你分..
    • 原梓番博客 在

      在Laravel框架中使用模型Model分表最简单的方法中评论 好久好久都没看友情链接申请了,今天刚看,已经添加。..
    • 博主 在

      佛跳墙vpn软件不会用?上不了网?佛跳墙vpn常见问题以及解决办法中评论 @1111老铁这个不行了,可以看看近期评论的其他文章..
    • 1111 在

      佛跳墙vpn软件不会用?上不了网?佛跳墙vpn常见问题以及解决办法中评论 网站不能打开,博主百忙中能否发个APP下载链接,佛跳墙或极光..
    • 2016-10
    • 2016-11
    • 2017-06
    • 2017-07
    • 2017-08
    • 2017-09
    • 2017-10
    • 2017-11
    • 2018-03
    • 2018-04
    • 2018-05
    • 2018-06
    • 2018-09
    • 2018-11
    • 2018-12
    • 2019-02
    • 2020-03
    • 2020-04
    • 2020-05
    • 2020-06
    • 2021-04
    • 2021-05
    • 2021-07
    • 2021-08
    • 2021-09
    • 2021-10
    • 2021-11
    • 2022-08
    • 2022-09
    • 2022-10
    • 2022-11
    • 2022-12
    • 2023-01
    • 2023-02
    • 2023-03
    • 2023-04
    • 2023-05
    • 2023-06
    • 2023-07
    • 2023-09
    • 2023-10
    • 2023-11
    • 2023-12
    • 2024-01
    • 2024-02
    • 2024-03
    • 2024-04
    Top

    Copyright·© 2019 侯体宗版权所有· 粤ICP备20027696号 PHP交流群

    侯体宗的博客