利用css3的animation实现点点点loading动画效果(二)

box-shadow实现的打点效果

简介

box-shadow理论上可以生成任意的图形效果,当然也就可以实现点点点的loading效果了。

实现原理

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

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

css代码

.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属性值一样,也就是跟文字颜色一样。

各浏览器实现的效果如图所示:

支持CSS3 animation动画的浏览器显示的就是打点动画效果;对于不支持的浏览器,IE7/IE8显示的是真实的字符..., IE9浏览器虽然也是CSS3生成,但是是静态的,没有动画效果;此乃渐进兼容。

不足之处

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

border + background实现的打点效果

实现原理

html代码

订单提交中<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个点 */
}

说明:

  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-right12像素,其他现代浏览器为width+margin-left也是12像素;
  6. 这里CSS代码主要用来展示原理,故没有显示-webkit-animation以及@-webkit-keyframes私有前缀,实际目前还是需要的;

参考地址:再说CSS3 animation实现点点点loading动画

https://github.com/tawian/text-spinners

时间: 2024-08-06 06:58:58

利用css3的animation实现点点点loading动画效果(二)的相关文章

酷炫的css3图标loading动画效果代码

css3 svg图标制作环形loading加载动画特效 绿色的css3动画加载图标代码 css3加载动画制作loading加载Android动画效果 jQuery css3预加载动画制作css3动画图标页面加载效果 css3加载动画特效制作css3 win8加载动画特效 css3加载动画效果制作loading动画效果代码 8种超炫css3加载动画代码_css3 loading动画效果代码 5个CSS3加载动画_css3网页加载动画图标下载 css3 Loading加载动画制作动态Loading阶

ios开发之简单实现loading动画效果

最近有朋友问我类似微信语音播放的喇叭动画和界面图片加载loading界面是怎样实现的,是不是就是一个gif图片呢!我的回答当然是否定了,当然不排除也有人用gif图片啊!下面我就来罗列三种实现loading动画效果的方法. 方法一:使用UIImageView自带的方法来实现,这也是我推荐的实现方法. NSMutableArray *array = [[NSMutableArray alloc] initWithObjects:[UIImage imageNamed:@"1.png"],[

loading 动画效果(收藏起来以后留着慢慢用)

动画效果一: html代码: <div class="spinner">   <div class="rect1"></div>   <div class="rect2"></div>   <div class="rect3"></div>   <div class="rect4"></div>  

CSS3感应鼠标的div背景闪烁动画效果

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <title>CSS3感应鼠标的div背景闪烁动画效果丨

Css3+jQuery打造的一款带动画效果的数字时钟

<!DOCTYPE HTML> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8"> <title>Css3+jQuery打造的一款带动画效果的数字时钟丨任E行F9行车记录仪|gopro官网|电影院座椅|</title> <style type="text/css&quo

css3实现的3中loading动画效果

一.css3中animation动画各种属性详解: animation Value:     [<animation-name> || <animation-duration> || <animation-timing-function> || <animation-delay> || <animation-iteration-count> || <animation-direction> || <animation-fill-

纯CSS3实现的8种Loading动画效果

转自赞生博客 效果如图: HTML代码部分(所有效果共用): <div class=”loader”>加载中…</div> 我们从左到右从上到下列出效果对应的CSS代码. 1#效果CSS代码: .load1 .loader,.load1 .loader:before,.load1 .loader:after {background: #FFF;-webkit-animation: load1 1s infinite ease-in-out;animation: load1 1s i

vue请求前的loading动画效果

参考: https://www.jianshu.com/p/304c665478b8 https://biigpongsatorn.github.io/#/vue-element-loading 1.安装 npm install vue-element-loading --save 2.使用vuex控制active(是否开启loading) // 用于控制是否显示加载动画 // 参考自https://www.jianshu.com/p/304c665478b8 const state = { c

Atitit Loading 动画效果

使用才场景,加载数据,以及显示警告灯.. 要有手动关闭按钮 <div class="spinner loading_part" style="display:none"> <p>正在抓取数据...</p> <div class="bounce1"></div> <div class="bounce2"></div> <div class=