css3加载spinner
使用代码制作一个加载旋转器spinner

实现的原理是:
1.两个圆圈,其中一个圆圈是使用pseudo元素(:before)产生
2.由pseudo元素生成的圆通过负数的z-index而作用在下面
3.由pseudo元素生成的圆圈有内置的阴影inset box-shadow
4.普通的圆圈有普通的阴影 regular box-shadow
5.“loading”是有overflow:hidden的strong标签
5.strong标签的长度由keyframe设置成动画,无限的reveal
6.文本通过line-height等于height的方法来垂直居中
7.旋转器是一个三角性,放在普通圆圈下面,以及放在由pseudo元素生成的圆圈的上面。
8.三角形通过keyframe设置成从0到360度无限旋转的动画。
理想状态下,三角形也应该设置成由pseudo元素生成,但是不幸的是到目前为止pseudo元素不支持动画。firefox可以transition它们,但是不能通过keyframe来设置动画(至少到目前为止不可以)。
效果图地址:https://css-tricks.com/examples/Loading/
html:
<!DOCTYPE html>
<html> <head>
<meta charset='UTF-8'> <title>Loading Thingy (WebKit)</title> <link rel='stylesheet' href='css/style.css'> <style>
#loading {
margin: 80px auto;
position: relative;
width: 100px;
height: 100px;
-webkit-border-radius: 50px;
-moz-border-radius: 50px;
border-radius: 50px;
background: #ccc;
font: 12px "Lucida Grande", Sans-Serif;
text-align: center;
line-height: 100px;
color: white;
-webkit-box-shadow: 0 0 5px rgba(0,0,0,0.5);
-moz-box-shadow: 0 0 5px rgba(0,0,0,0.5);
box-shadow: 0 0 5px rgba(0,0,0,0.5); }
#loading:before {
content: "";
position: absolute;
left: -20px;
top: -20px;
bottom: -20px;
right: -20px;
-webkit-border-radius: 70px;
-moz-border-radius: 70px;
border-radius: 70px;
background: #eee;
z-index: -2;
-webkit-box-shadow: inset 0 0 10px rgba(0,0,0,0.2);
-moz-box-shadow: inset 0 0 10px rgba(0,0,0,0.2);
box-shadow: inset 0 0 10px rgba(0,0,0,0.2);
}
#loading span {
position: absolute;
width: 0;
height: 0;
border-left: 50px solid transparent;
border-right: 50px solid transparent;
border-top: 80px solid rgba(255,255,255,0.7);
z-index: -1;
top: -28px;
left: 0px;
-webkit-animation: ticktock 5s linear infinite;
-webkit-transform-origin: 50px 80px;
}
#loading strong {
overflow: hidden;
display: block;
margin: 0 auto;
-webkit-animation: expand 2.5s linear infinite;
} @-webkit-keyframes expand {
0% {
width: 0;
}
100% {
width: 60px;
}
} @-webkit-keyframes ticktock {
0% {
-webkit-transform: rotate(0);
}
100% {
-webkit-transform: rotate(360deg);
}
} </style> </head> <body> <div id="demo-top-bar"> <div id="demo-bar-inside"> <h2 id="demo-bar-badge">
<a href="/">CSS-Tricks Example</a>
</h2> <div id="demo-bar-buttons">
</div> </div> </div>
<div id="page-wrap"> <div id="loading"><strong>loading...</strong><span></span></div> </div> <style type="text/css" style="display: none !important;">
* {
margin: 0;
padding: 0;
}
body {
overflow-x: hidden;
}
#demo-top-bar {
text-align: left;
background: #222;
position: relative;
zoom: 1;
width: 100% !important;
z-index: 6000;
padding: 20px 0 20px;
}
#demo-bar-inside {
width: 960px;
margin: 0 auto;
position: relative;
overflow: hidden;
}
#demo-bar-buttons {
padding-top: 10px;
float: right;
}
#demo-bar-buttons a {
font-size: 12px;
margin-left: 20px;
color: white;
margin: 2px 0;
text-decoration: none;
font: 14px "Lucida Grande", Sans-Serif !important;
}
#demo-bar-buttons a:hover,
#demo-bar-buttons a:focus {
text-decoration: underline;
}
#demo-bar-badge {
display: inline-block;
width: 302px;
padding: 0 !important;
margin: 0 !important;
background-color: transparent !important;
}
#demo-bar-badge a {
display: block;
width: 100%;
height: 38px;
border-radius: 0;
bottom: auto;
margin: 0;
background: url(/images/examples-logo.png) no-repeat;
background-size: 100%;
overflow: hidden;
text-indent: -9999px;
}
#demo-bar-badge:before, #demo-bar-badge:after {
display: none !important;
}
</style>
</body> </html>
css:
/*
CSS-Tricks Example
by Chris Coyier
http://css-tricks.com
*/ * { margin:; padding:; }
body { font: 14px Georgia, serif; } article, aside, figure, footer, header, hgroup,
menu, nav, section { display: block; } #page-wrap { width: 960px; margin: 150px auto; }
原文:https://css-tricks.com/css3-loading-spinner/
css3加载spinner的更多相关文章
- 纯css3加载动画
<!DOCTYPE html><html> <head> <meta charset="utf-8"> <meta name= ...
- 纯css3 加载loading动画特效
最近项目中要实现当页面还没有加载完给用户提示正在加载的loading,本来是想做个图片提示的,但是图片如果放大电脑的分辨率就会感觉到很虚,体验效果很不好.于是就采用css3+js实现这个loading ...
- css3加载ing动画
项目中ajax交互成功前总会需要给用户提醒,比如请稍候.正在加载中等等,那个等待的动图以前项目中用的是gif,在移动端画质很渣,有毛边,于是在新项目中用css3展示加载中的动画效果. function ...
- javascript,css3加载动画
html代码 <!DOCTYPE html> <html> <head> <meta charset="utf-8"> <me ...
- CSS3加载动画
图1 通常我们都使用gif格式的图片或者使用Ajax来实现诸如这类的动态加载条,但是现在CSS3也可以完成,并且灵活性更大. 选1个例子看看怎么实现的吧: 效果图: 图2 代码: 使用1个名为'l ...
- css3加载中
.loader { margin: 6em auto; font-size: 10px; position: relative; text-indent: -9999em; border-top: 1 ...
- 兼容ie10及以上css3加载进度动画
html <div class="spinner"> <div class="rect1"></div> < ...
- css3 加载动画效果
Loading 动画效果一 HTML 代码: <div class="spinner"> <div class="rect1&quo ...
- CSS3 加载进度样式
<html> <head> <style type="text/css"> body{ background-color: green; } . ...
随机推荐
- Arbitrage - poj 2240 (Bellman-ford)
Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 17374 Accepted: 7312 Description Ar ...
- 【Python + Mysql】之用pymysql库连接Mysql数据库并进行增删改查操作
用pip下载pymysql并引用 具体请参考文章: <Python之MySQL数据库增删改查操作> <python3.6 使用 pymysql 连接 Mysql 数据库及 简单的增删 ...
- js关于事件的一些总结(系列一)
今天小弟在这里说一下 js 关于事件的一些总结 在这里直接上代码 省去啰嗦的步骤以免看烦了 总结的不好希望大家见谅 一.事件的默认事件 事件的默认事件是什么? 就是a标签有一个链接事件 inpu ...
- 杭电OJ(HDU)-ACMSteps-Chapter Three-《FatMouse' Trade》《今年暑假不AC》《排名》《开门人和关门人》
watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQvY2Fpc2luaV92Yw==/font/5a6L5L2T/fontsize/400/fill/I0JBQk ...
- 列表按照字母排序检索SideBar
项目中要求列表按照ABCD这种字母排序检索的功能,看了大神写的,瞬间崇拜了,接下来借大家参考参考了 首先是自定义view sidebar /** * @author J *一个自定义view 实现a- ...
- jquery 与javascript关系 ①取元素 ②操作内容 ③操作属性 ④操作 样式 ⑤ 事件 点击变色
jQuery的min版本和原版功能是一样的,min版主要应用于已经开发成的网页中,而非min版 的文件比较大,里面有整洁的代码书写规范和注释,主要应用于脚本开发过程当中. JQuery是继protot ...
- 一个关于运维人员做事的很好的case,拿出来和大家共勉
很久没有写KM了,最近lester这边在梳理CDB这边存在的问题,并推动那些问题解决措施的落地.无疑当前CDB存在比较多的问题,也有很多坑.需要我们运维和开发的同学多思考问题的根源和解决办法,并付诸实 ...
- poj3292
Semi-prime H-numbers Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 8677 Accepted: 3 ...
- 九度OJ 1336:液晶屏裁剪 (GCD)
时间限制:1 秒 内存限制:32 兆 特殊判题:否 提交:983 解决:228 题目描述: 苏州某液晶厂一直生产a * b大小规格的液晶屏幕,由于该厂的加工工艺限制,液晶屏的边长都为整数.最近由于市场 ...
- [Oracle]根据字段值全库搜索相关数据表和字段
这个需求比较冷门,但对于在某些特定的情况下,还是会有这样的需要的.好在Oracle实现还比较方便,用存储过程则轻松实现. 查询字符串: create or replace procedure sear ...