几种炫酷的加载动画

动画一

在这里插入图片描述

// An highlighted block
<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <title>Document</title>
    <style>
    body {
        background: #111;
        overflow: hidden;
    }

    canvas {
        bottom: 0;
        left: 0;
        margin: auto;
        position: absolute;
        right: 0;
        top: 0;
    }
    </style>
</head>

<body>
    <!-- <div></div> -->
</body>

</html>
<script>
var $ = {};

$.Particle = function(opt) {
    this.radius = 7;
    this.x = opt.x;
    this.y = opt.y;
    this.angle = opt.angle;
    this.speed = opt.speed;
    this.accel = opt.accel;
    this.decay = 0.01;
    this.life = 1;
};

$.Particle.prototype.step = function(i) {
    this.speed += this.accel;
    this.x += Math.cos(this.angle) * this.speed;
    this.y += Math.sin(this.angle) * this.speed;
    this.angle += $.PI / 64;
    this.accel *= 1.01;
    this.life -= this.decay;

    if (this.life <= 0) {
        $.particles.splice(i, 1);
    }
};

$.Particle.prototype.draw = function(i) {
    $.ctx.fillStyle = $.ctx.strokeStyle = 'hsla(' + ($.tick + (this.life * 120)) + ', 100%, 60%, ' + this.life + ')';
    $.ctx.beginPath();
    if ($.particles[i - 1]) {
        $.ctx.moveTo(this.x, this.y);
        $.ctx.lineTo($.particles[i - 1].x, $.particles[i - 1].y);
    }
    $.ctx.stroke();

    $.ctx.beginPath();
    $.ctx.arc(this.x, this.y, Math.max(0.001, this.life * this.radius), 0, $.TWO_PI);
    $.ctx.fill();

    var size = Math.random() * 1.25;
    $.ctx.fillRect(~~(this.x + ((Math.random() - 0.5) * 35) * this.life), ~~(this.y + ((Math.random() - 0.5) * 35) * this.life), size, size);
}

$.step = function() {
    $.particles.push(new $.Particle({
        x: $.width / 2 + Math.cos($.tick / 20) * $.min / 2,
        y: $.height / 2 + Math.sin($.tick / 20) * $.min / 2,
        angle: $.globalRotation + $.globalAngle,
        speed: 0,
        accel: 0.01
    }));

    $.particles.forEach(function(elem, index) {
        elem.step(index);
    });

    $.globalRotation += $.PI / 6;
    $.globalAngle += $.PI / 6;
};

$.draw = function() {
    $.ctx.clearRect(0, 0, $.width, $.height);

    $.particles.forEach(function(elem, index) {
        elem.draw(index);
    });
};

$.init = function() {
    $.canvas = document.createElement('canvas');
    $.ctx = $.canvas.getContext('2d');
    $.width = 300;
    $.height = 300;
    $.canvas.width = $.width * window.devicePixelRatio;
    $.canvas.height = $.height * window.devicePixelRatio;
    $.canvas.style.width = $.width + 'px';
    $.canvas.style.height = $.height + 'px';
    $.ctx.scale(window.devicePixelRatio, window.devicePixelRatio);
    $.min = $.width * 0.5;
    $.particles = [];
    $.globalAngle = 0;
    $.globalRotation = 0;
    $.tick = 0;
    $.PI = Math.PI;
    $.TWO_PI = $.PI * 2;
    $.ctx.globalCompositeOperation = 'lighter';
    document.body.appendChild($.canvas);
    $.loop();
};

$.loop = function() {
    requestAnimationFrame($.loop);
    $.step();
    $.draw();
    $.tick++;
};

$.init();
</script>

动画二

在这里插入图片描述

<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <title>Document</title>
    <style type="text/css">
    body,html {
        background: #000000;
        padding-top: 50px;
    }

    .spinner {
        position: relative;
        margin: auto;
        box-sizing: border-box;
        background-clip: padding-box;
        width: 200px;
        height: 200px;
        border-radius: 100px;
        border: 4px solid rgba(255, 255, 255, 0.1);
        -webkit-mask: linear-gradient(rgba(0, 0, 0, 0.1), #000000 90%);
        transform-origin: 50% 60%;
        transform: perspective(200px) rotateX(66deg);
        animation: spinner-wiggle 1.2s infinite;
    }

    .spinner:before,
    .spinner:after {
        content: "";
        position: absolute;
        margin: -4px;
        box-sizing: inherit;
        width: inherit;
        height: inherit;
        border-radius: inherit;
        opacity: .05;
        border: inherit;
        border-color: transparent;
        animation: spinner-spin 1.2s cubic-bezier(0.6, 0.2, 0, 0.8) infinite, spinner-fade 1.2s linear infinite;
    }

    .spinner:before {
        border-top-color: #66e6ff;
    }

    .spinner:after {
        border-top-color: #f0db75;
        animation-delay: 0.3s;
    }

    @keyframes spinner-spin {
        100% {
            transform: rotate(360deg);
        }
    }

    @keyframes spinner-fade {
        20% {
            opacity: .1;
        }

        40% {
            opacity: 1;
        }

        60% {
            opacity: .1;
        }
    }
    </style>
</head>

<body>
    <div class="spinner"></div>
</body>

</html>

动画三

加载加页面开合
css

<style type="text/css">
   .chromeframe {
     margin: 0.2em 0;
     background: #ccc;
     color: #000;
     padding: 0.2em 0;}
   #loader-wrapper {
     position: fixed;
     top: 0;
     left: 0;
     width: 100%;
     height: 100%;
     z-index:999999;}
   #loader {
     display: block;
     position: relative;
     left: 50%;
     top: 50%;
     width: 150px;
     height: 150px;
     margin: -75px 0 0 -75px;
     border-radius: 50%;
     border: 3px solid transparent;
     /* COLOR 1 */
     border-top-color: #000;
     -webkit-animation: spin 2s linear infinite; /* Chrome, Opera 15+, Safari 5+ */
     -ms-animation: spin 2s linear infinite; /* Chrome, Opera 15+, Safari 5+ */
     -moz-animation: spin 2s linear infinite; /* Chrome, Opera 15+, Safari 5+ */
     -o-animation: spin 2s linear infinite; /* Chrome, Opera 15+, Safari 5+ */
     animation: spin 2s linear infinite; /* Chrome, Firefox 16+, IE 10+, Opera */
     z-index:1001;}
   #loader:before {
     content: "";
     position: absolute;
     top: 5px;
     left: 5px;
     right: 5px;
     bottom: 5px;
     border-radius: 50%;
     border: 3px solid transparent;
     /* COLOR 2 */
     border-top-color: #000;
     -webkit-animation: spin 3s linear infinite; /* Chrome, Opera 15+, Safari 5+ */
     -moz-animation: spin 3s linear infinite; /* Chrome, Opera 15+, Safari 5+ */
     -o-animation: spin 3s linear infinite; /* Chrome, Opera 15+, Safari 5+ */
     -ms-animation: spin 3s linear infinite; /* Chrome, Opera 15+, Safari 5+ */
     animation: spin 3s linear infinite; /* Chrome, Firefox 16+, IE 10+, Opera */}
   #loader:after {
     content: "";
     position: absolute;
     top: 15px;
     left: 15px;
     right: 15px;
     bottom: 15px;
     border-radius: 50%;
     border: 3px solid transparent;
     border-top-color: #000;
     /* COLOR 3 */
     -moz-animation: spin 1.5s linear infinite; /* Chrome, Opera 15+, Safari 5+ */
     -o-animation: spin 1.5s linear infinite; /* Chrome, Opera 15+, Safari 5+ */
     -ms-animation: spin 1.5s linear infinite; /* Chrome, Opera 15+, Safari 5+ */
     -webkit-animation: spin 1.5s linear infinite; /* Chrome, Opera 15+, Safari 5+ */
     animation: spin 1.5s linear infinite; /* Chrome, Firefox 16+, IE 10+, Opera */}


   @-webkit-keyframes spin {
     0%{
       -webkit-transform: rotate(0deg);  /* Chrome, Opera 15+, Safari 3.1+ */
       -ms-transform: rotate(0deg);  /* IE 9 */
       transform: rotate(0deg);  /* Firefox 16+, IE 10+, Opera */
     }100%{
        -webkit-transform: rotate(360deg);  /* Chrome, Opera 15+, Safari 3.1+ */
        -ms-transform: rotate(360deg);  /* IE 9 */
        transform: rotate(360deg);  /* Firefox 16+, IE 10+, Opera */}
   }

   @keyframes spin {
     0%{
       -webkit-transform: rotate(0deg);  /* Chrome, Opera 15+, Safari 3.1+ */
       -ms-transform: rotate(0deg);  /* IE 9 */
       transform: rotate(0deg);  /* Firefox 16+, IE 10+, Opera */
     }100%{
        -webkit-transform: rotate(360deg);  /* Chrome, Opera 15+, Safari 3.1+ */
        -ms-transform: rotate(360deg);  /* IE 9 */
        transform: rotate(360deg);  /* Firefox 16+, IE 10+, Opera */}
   }


   #loader-wrapper .loader-section {
     position: fixed;
     top: 0;
     width: 51%;
     height: 100%;
     background: #fdc73e; /* Old browsers */
     z-index: 1000;
     -webkit-transform: translateX(0);  /* Chrome, Opera 15+, Safari 3.1+ */
     -ms-transform: translateX(0);  /* IE 9 */
     transform: translateX(0);  /* Firefox 16+, IE 10+, Opera */}
   #loader-wrapper .loader-section.section-left {left: 0;}
   #loader-wrapper .loader-section.section-right {right: 0;}

   /* Loaded */
   .loaded #loader-wrapper .loader-section.section-left {
     -webkit-transform: translateX(-100%);  /* Chrome, Opera 15+, Safari 3.1+ */
     -ms-transform: translateX(-100%);  /* IE 9 */
     transform: translateX(-100%);  /* Firefox 16+, IE 10+, Opera */
     -webkit-transition: all 0.7s 0.3s cubic-bezier(0.645, 0.045, 0.355, 1.000);
     transition: all 0.7s 0.3s cubic-bezier(0.645, 0.045, 0.355, 1.000);}
   .loaded #loader-wrapper .loader-section.section-right {
     -webkit-transform: translateX(100%);  /* Chrome, Opera 15+, Safari 3.1+ */
     -ms-transform: translateX(100%);  /* IE 9 */
     transform: translateX(100%);  /* Firefox 16+, IE 10+, Opera */
     -webkit-transition: all 0.7s 0.3s cubic-bezier(0.645, 0.045, 0.355, 1.000);
     transition: all 0.7s 0.3s cubic-bezier(0.645, 0.045, 0.355, 1.000);}
   .loaded #loader {
     opacity: 0;
     -webkit-transition: all 0.3s ease-out;
     transition: all 0.3s ease-out;}
   .loaded #loader-wrapper {
     visibility: hidden;
     -webkit-transform: translateY(-100%);  /* Chrome, Opera 15+, Safari 3.1+ */
     -ms-transform: translateY(-100%);  /* IE 9 */
     transform: translateY(-100%);  /* Firefox 16+, IE 10+, Opera */
     -webkit-transition: all 0.3s 1s ease-out;
     transition: all 0.3s 1s ease-out;}
   /* JavaScript Turned Off */
   .no-js #loader-wrapper {display: none;}
   .no-js h1 {color: #222222;}
   #loader-wrapper .load_title {
     font-family:'Open Sans';
     color:#000; font-size:19px; width:100%; text-align:center; z-index:9999999999999; position:absolute; top:60%; opacity:1; line-height:30px; }
   #loader-wrapper .load_title span {  font-weight:normal; font-style:italic; font-size:13px; color:#000; opacity:0.5;}
 </style>

html

<div id="loader-wrapper">
  <div id="loader"></div>
  <div class="loader-section section-left"></div>
  <div class="loader-section section-right"></div>
  <div class="load_title">modure loading...</div>
</div>

js(注意:这个是基于vue加载动画,这段代码在app.vue中)

 created () {
    // document.body.removeChild(document.getElementById('Loading'))
    document.getElementsByTagName('body')[0].className += 'loaded'
    if (document.getElementsByClassName('.load_title')[0] !== undefined) {
      document.getElementsByClassName('.load_title')[0].remove()
    }
  },

动画5j

1.在入口文件index.html中加入loading动画:
<!DOCTYPE html>
<html>
  <head>
    <meta charset="utf-8">
    <meta name="renderer" content="webkit|ie-comp|ie-stand">
    <meta content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=0" name="viewport">
    <!--浏览器兼容模式用最新的文档渲染模式-->
    <meta http-equiv="X-UA-Compatible" content ="IE=edge"/>
    <title></title>
    <style type="text/css">
      #Loading {
        top:50%;
        left:50%;
        position: absolute;
        -webkit-transform: translateY(-50%)  translateX(-50%);
        transform: translateY(-50%)  translateX(-50%);
        z-index:100;
      }
      @-webkit-keyframes ball-beat {
        50% {
          opacity: 0.2;
          -webkit-transform: scale(0.75);
          transform: scale(0.75); }

        100% {
          opacity: 1;
          -webkit-transform: scale(1);
          transform: scale(1); } }

      @keyframes ball-beat {
        50% {
          opacity: 0.2;
          -webkit-transform: scale(0.75);
          transform: scale(0.75); }

        100% {
          opacity: 1;
          -webkit-transform: scale(1);
          transform: scale(1); } }

      .ball-beat > div {
        background-color: #279fcf;
        width: 15px;
        height: 15px;
        border-radius: 100% !important;
        margin: 2px;
        -webkit-animation-fill-mode: both;
        animation-fill-mode: both;
        display: inline-block;
        -webkit-animation: ball-beat 0.7s 0s infinite linear;
        animation: ball-beat 0.7s 0s infinite linear; }
      .ball-beat > div:nth-child(2n-1) {
        -webkit-animation-delay: 0.35s !important;
        animation-delay: 0.35s !important; }
    </style>

  </head>
  <body>
    <div id="Loading">
      <div class="loader-inner ball-beat">
        <div></div>
        <div></div>
        <div></div>
      </div>
    </div>
    <div id="app"></div>
    <!-- built files will be auto injected -->
  </body>
</html>
2.在app.vue的created方法中:
created() {  document.body.removeChild(document.getElementById('Loading'))   
}

查看原文:http://www.ibloger.net/article/401.html

相关阅读:
30种CSS3炫酷页面预加载loading动画特效(推荐):http://www.ibloger.net/article/1558.html
Loaders.css 多种纯CSS加载进度动画效果:http://www.ibloger.net/article/1568.html
load-awesome 53种纯CSS3预加载页面loading指示器动画特:效http://www.ibloger.net/article/1800.html
CSS3-Preloaders 6种CSS3预加载Loading指示器动画特效:http://www.ibloger.net/article/1556.html
按钮特效 基于SVG和Segment.js的Loading加载:http://www.ibloger.net/article/1554.html

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值