css3效果:animate实现点点点loading动画效果(二)

box-shadow实现的打点效果

简介

box-shadow理论上能够生成任意的图形效果,固然也就能够实现点点点的loading效果了。css

实现原理

html代码,首先须要写以下html代码以及class类名:html

订单提交中<span class="dotting"></span>

css代码css3

.dotting {
    display: inline-block; min-width: 2px; min-height: 2px;
    box-shadow: 2px 0 currentColor, 6px 0 currentColor, 10px 0 currentColor; /* for IE9+, ..., 3个点 */
    animation: dot 4s infinite step-start both; /* for IE10+, ... */
    *zoom: expression(this.innerHTML = '...'); /*  for IE7. 若无需兼容IE7, 此行删除 */
}
.dotting:before { content: '...'; } /* for IE8. 若无需兼容IE8, 此行以及下一行删除*/
.dotting::before { content: ''; } /* for IE9+ 覆盖 IE8 */
:root .dotting { margin-right: 8px; } /* for IE9+,FF,CH,OP,SF 占据空间*/

@keyframes dot {
    25% { box-shadow: none; }                                  /* 0个点 */
    50% { box-shadow: 2px 0 currentColor; }                    /* 1个点 */
    75% { box-shadow: 2px 0 currentColor, 6px 0 currentColor;  /* 2个点 */ }
}

这里用到了currentColor这个关键字,IE9+浏览器支持,其可让CSS生成的图形的颜色跟所处环境的color属性值同样,也就是跟文字颜色同样。git

各浏览器实现的效果如图所示:
图片描述github

不足之处

虽然几乎全部浏览器都有模有样,可是,从效果上讲,仍是有瑕疵的,IE10+以及FireFox浏览器下的点的边缘有些虚(参见下截图),虽然CSS代码并无设置盒阴影模糊。这种羽化现象可让IE以及FireFox在大数值盒阴影时候效果更接近photoshop的阴影效果;可是,在小尺寸阴影时候,并非咱们想要的。
图片描述web

border + background实现的打点效果

实现原理

html代码express

订单提交中<span class="dotting"></span>

css代码浏览器

.dotting {
    display: inline-block; width: 10px; min-height: 2px;
    padding-right: 2px;
    border-left: 2px solid currentColor; border-right: 2px solid currentColor;   
    background-color: currentColor; background-clip: content-box;
    box-sizing: border-box;
    animation: dot 4s infinite step-start both;
    *zoom: expression(this.innerHTML = '...'); /* IE7 */
}
.dotting:before { content: '...'; } /* IE8 */
.dotting::before { content: ''; }
:root .dotting { margin-left: 2px; padding-left: 2px; } /* IE9+ */

@keyframes dot {
    25% { border-color: transparent; background-color: transparent; }          /* 0个点 */
    50% { border-right-color: transparent; background-color: transparent; }    /* 1个点 */
    75% { border-right-color: transparent; }                                   /* 2个点 */
}

说明:wordpress

1.一样是4秒动画,每秒钟显示1个点;
2.IE7/IE8实现原理跟上面box-shadow方法一致,都是内容生成,若是无需兼容IE7/IE8, 能够按照第一个例子CSS代码注释说明删除一些CSS;
3.currentColor关键字可让图形字符化,必不可少;
4.最大功臣是CSS3 background-clip属性,可让IE9+浏览器下左右padding没有背景色,因而造成了等分打点效果。
5.box-sizing是让现代浏览器和IE7/IE8占据宽度彻底同样的功臣:IE7/IE8实际宽度是width+padding-right为12像素,其余现代浏览器为width+margin-left也是12像素;
6.这里CSS代码主要用来展现原理,故没有显示-webkit-animation以及@-webkit-keyframes私有前缀,实际目前仍是须要的;动画

参考地址:再说CSS3 animation实现点点点loading动画
https://github.com/tawian/tex...

相关文章
相关标签/搜索