图片/图形

CSS3炫酷页面预加载loading动画特效

阿里云


这是一组效果非常炫酷的 CSS3 页面预加载 loading 动画特效。该特效共有 30 种不同的 loading 效果。所有的加载动画都是使用 CSS3 来完成,jQurey 代码只是用于隐藏加载动画。当你点击页面的任何一个地方时,loading 动画就会被隐藏。这 30 种 loading 动画分为 3 组:方形加载动画特效、圆形加载动画特效和长条形加载动画特效。每一种效果都有一个单独的页面,你可以对应查看每种效果的 CSS 代码。

HTML 结构

下面是第一种效果的制作方式。所有的 DEMO 都是使用嵌套 div 的 HTML 结构。在第一个 DEMO 中,嵌套了 4 层 div 元素,其中最里层的 div#object 是用于动画的元素。

也想出现在这里?联系我们
创客主机
  1. <div id="loading">
  2.   <div id="loading-center">
  3.     <div id="loading-center-absolute">
  4.       <div id="object"></div>
  5.     </div>
  6.   </div>
  7. </div>

外层的 div 元素主要用于定位。

CSS 样式

首先要设置最外层的 div 的定位方式为固定定位方式,这样方便它里面的元素制作各种动画效果。

  1. #loading{
  2.   background-color: #bd4932;
  3.   height: 100%;
  4.   width: 100%;
  5.   position: fixed;
  6.   z-index: 1;
  7.   margin-top: 0px;
  8.   top: 0px;
  9. }

接着分别设置第二层和第三层 div 元素。第二层 div 元素设置为相对定位,宽度和高度均为 100%。第三层 div 是实际动画元素的包裹元素,它设置为绝度定位,并且位置居中。

  1. #loading-center{
  2.   width: 100%;
  3.   height: 100%;
  4.   position: relative;
  5. }
  6. #loading-center-absolute {
  7.   position: absolute;
  8.   left: 50%;
  9.   top: 50%;
  10.   height: 200px;
  11.   width: 200px;
  12.   margin-top: -100px;
  13.   margin-left: -100px;
  14. }

最后,使用 keyframes 帧动画使 div#object 元素动起来,@-webkit-keyframes animate 是为了兼容 webkit 内核的浏览器。@keyframes animate 则是为了兼容 IE 浏览器。

  1. #object{
  2.   width: 80px;
  3.   height: 80px;
  4.   background-color: #FFF;
  5.   -webkit-animation: animate 1s infinite ease-in-out;
  6.   animation: animate 1s infinite ease-in-out;
  7.   margin-right: auto;
  8.   margin-left: auto;
  9.   margin-top: 60px;
  10. }
  11. @-webkit-keyframes animate {
  12.   0% { -webkit-transform: perspective(160px); }
  13.   50% { -webkit-transform: perspective(160px) rotateY(-180deg); }
  14.   100% { -webkit-transform: perspective(160px) rotateY(-180deg) rotateX(-180deg); }
  15. }
  16.  
  17. @keyframes animate {
  18.   0% { 
  19.     transform: perspective(160px) rotateX(0deg) rotateY(0deg);
  20.     -webkit-transform: perspective(160px) rotateX(0deg) rotateY(0deg); 
  21.   } 50% { 
  22.     transform: perspective(160px) rotateX(-180deg) rotateY(0deg);
  23.     -webkit-transform: perspective(160px) rotateX(-180deg) rotateY(0deg) ;
  24.   } 100% { 
  25.     transform: perspective(160px) rotateX(-180deg) rotateY(-180deg);
  26.     -webkit-transform: perspective(160px) rotateX(-180deg) rotateY(-180deg);
  27.   }
  28. }

JAVASCRIPT

插件中还使用了一些 jQuery 代码来隐藏 loading 效果。

  1. $(window).load(function() {
  2.   $("#loading-center").click(function() {
  3.   $("#loading").fadeOut(500);
  4.   })    
  5. });

在实际应用中,你可能需要这样使用这些 Loading 效果:

  1. $(window).load(function() {
  2.    $("#loading").fadeOut(500);
  3. })

上面的代码表示在页面加载完成之后 0.5 秒的时间内将 loading 动画淡入淡出隐藏起来。

CSS3 炫酷页面预加载 loading 动画特效

已有 497 人购买
查看演示升级 VIP立刻购买

演示地址 下载地址
收藏
(0)

发表回复

热销模板

Ashade - 作品展示摄影相册WordPress汉化主题
LensNews

本站承接 WordPress / PbootCMS / DedeCMS 等
系统建站、仿站、开发、定制等业务!