时间:2021-07-01 10:21:17 帮助过:55人阅读
案例一:loading动画效果
html代码:
css样式:
案例二:圆形放大或缩小的loading效果
html代码:
css样式:
.spinner {  width: 60px;  height: 60px;   position: relative;  margin: 100px;} .double-bounce1, .double-bounce2 {  width: 100%;  height: 100%;  border-radius: 50%;  background-color: #67CF22;  opacity: 0.6;  position: absolute;  top: 0;  left: 0;     -webkit-animation: bounce 2.0s infinite ease-in-out;  animation: bounce 2.0s infinite ease-in-out;} .double-bounce2 {  -webkit-animation-delay: -1.0s;  animation-delay: -1.0s;} @-webkit-keyframes bounce {  0%, 100% { -webkit-transform: scale(0.0) }  50% { -webkit-transform: scale(1.0) }} @keyframes bounce {  0%, 100% {     transform: scale(0.0);    -webkit-transform: scale(0.0);  } 50% {     transform: scale(1.0);    -webkit-transform: scale(1.0);  }}      
看了上面的两个案例,我们知道了什么是多个物件循环动画,也可以知道,通过animation-delay延迟,我们可以让多个物体保持步调一致的运动效果,但是看了动画和延迟却还是不知道怎么设置,可能你会想象物体运行的帧,确实我分析的时候也是这么想的。
要讲清楚这个,我们得先知道几个概率(参数),animation动画持续时间t1,每个物体延迟时间差t2,物体个数n
t2 = t1/n
平均关键帧的百分比为 100%/n
把以上的这几个点,理解清楚了之后,其实我们应该就清楚了怎么去写多个物体循环了,举个例子:
html代码:
css代码:
        ul{list-style:none;padding:0;margin:0;}        ul>li{            width:50px;            height:50px;            margin-bottom:20px;            background:orange;            -webkit-animation:scale 3s linear infinite;        }        .on2{            -webkit-animation-delay:0.5s;        }        .on3{            -webkit-animation-delay:1s;        }        .on4{            -webkit-animation-delay:1.5s;        }        .on5{            -webkit-animation-delay:2s;        }        .on6{            -webkit-animation-delay:2.5s;        }        @-webkit-keyframes scale{            0%,33.4%{width:50px;height:50px;}            16.7%{width:80px;height:80px;}        }      这个例子其实是6个物体循环的动画,我们控制在每次100%/16的点做不同物体变化效果就行了,即16.7%、33.4%、50.1%、66.8%、83.5、100.2%(这里由于不整除,多出了一部分,就当近似于)
而且,我们想一开始就看到元素开始动,那么我们就要将这16.7%前置,则得出了
      @-webkit-keyframes scale{            0%,33.4%{width:50px;height:50px;}            16.7%{width:80px;height:80px;}        }      最后可能也不是讲的很清楚,还请不理解的多做几个例子,多想想就通了,共勉。
留几个有关css3动画写的比较好的文章:
经验分享:多屏复杂动画CSS技巧三则
涨姿势!CSS3动画帧数科学计算法
【原】移动web动画设计的一点心得??css3实现跑步