等待效果传统的做法是做了N张不同大小的gif图。用javascript去判断屏的大小,然后选择适当的gif图片,这样做的缺点是很显的,说多了都是泪。现在我要做的,就是换成css3去实现这个效果。下面看效果图:
复制代码 代码如下:
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
<meta name="viewport" content="width=device-width, initial-scale=1, user-scalable=0, maximum-scale=3">
<meta name="apple-mobile-web-app-capable" content="yes">
<meta name="apple-mobile-web-app-status-bar-style" content="black">
<style type="text/css">
body {
margin: 0;
padding: 0;
}
/* for busy */
#busyIcon {
z-index:99999;
position:absolute;
top:0;left:0;
width:100%;
height:100%;
background-color: rgba(0,0,0,0.7);
}
.container {
width:100px;
height: 100px;
background-color:black;
opacity: 0.8;
margin-top: -50px;
margin-left: -50px;
position: absolute;
top:50%;left:50%;
-webkit-border-radius: 10%;
}
.top,.base {
height: 30%;
}
.spinner {
height: 40%;
width: 40%;
position: relative;
margin: 0 auto;
}
.spinner div {
width: 12%;
height: 26%;
background-color: white;
position: absolute;
left: 44.5%;
top: 37%;
opacity: 0;
-webkit-border-radius: 30%;
-webkit-animation: fade 1s linear infinite;
}
.spinner div.bar1 {-webkit-transform:rotate(0deg) translate(0, -142%); -webkit-animation-delay: 0s;}
.spinner div.bar2 {-webkit-transform:rotate(30deg) translate(0, -142%); -webkit-animation-delay: -0.9167s;}
.spinner div.bar3 {-webkit-transform:rotate(60deg) translate(0, -142%); -webkit-animation-delay: -0.833s;}
.spinner div.bar4 {-webkit-transform:rotate(90deg) translate(0, -142%); -webkit-animation-delay: -0.75s;}
.spinner div.bar5 {-webkit-transform:rotate(120deg) translate(0, -142%); -webkit-animation-delay: -0.667s;}
.spinner div.bar6 {-webkit-transform:rotate(150deg) translate(0, -142%); -webkit-animation-delay: -0.5833s;}
.spinner div.bar7 {-webkit-transform:rotate(180deg) translate(0, -142%); -webkit-animation-delay: -0.5s;}
.spinner div.bar8 {-webkit-transform:rotate(210deg) translate(0, -142%); -webkit-animation-delay: -0.41667s;}
.spinner div.bar9 {-webkit-transform:rotate(240deg) translate(0, -142%); -webkit-animation-delay: -0.333s;}
.spinner div.bar10 {-webkit-transform:rotate(270deg) translate(0, -142%); -webkit-animation-delay: -0.25s;}
.spinner div.bar11 {-webkit-transform:rotate(300deg) translate(0, -142%); -webkit-animation-delay: -0.1667s;}
.spinner div.bar12 {-webkit-transform:rotate(330deg) translate(0, -142%); -webkit-animation-delay: -0.0833s;}
@-webkit-keyframes fade {
from {opacity: 1;}
to {opacity: 0.25;}
}
/*End busy*/
</style>
</head>
<body>
<div id="busyIcon">
<div class="container">
<div class="top"></div>
<div class="spinner">
<div class="bar1"></div>
<div class="bar2"></div>
<div class="bar3"></div>
<div class="bar4"></div>
<div class="bar5"></div>
<div class="bar6"></div>
<div class="bar7"></div>
<div class="bar8"></div>
<div class="bar9"></div>
<div class="bar10"></div>
<div class="bar11"></div>
<div class="bar12"></div>
</div>
<div class="base"></div>
</div>
</div>
</body>
</html>
这里是为了方便演示,对浏览器的兼容省略了,实际项目中,我用js进行了封装,方便调用和控制。
本例只记录一下原理,封装后的代码就不贴了。下面发一张应用中的效果裁图。
css3能做的还有很多,以后慢慢分享。
本文地址:http://www.45fan.com/bcdm/9550.html