当前位置:网站首页>Simple loading animation
Simple loading animation
2022-07-07 17:38:00 【Zi Yu】
style
.page-loading{
position: fixed;
top: 0;
left: 0;
width: 100%;
z-index: 9999;
height: 100%;
background-color: rgba(0, 0, 0, 0.4);
}
.page-loading-div{
width: 100%;
height: 100px;
position: absolute;
top: 50%;
left: 0;
margin-top: -50px;
}
.page-loading-box{
width: 100px;
height: 100px;
line-height: 100px;
font-size: 80px;
color: rgba(255,255,255,0.4);
text-align: center;
margin: 0 auto;
border-radius: 100px;
overflow: hidden;
opacity: 0.8;
position: relative;
background-color: rgba(255,255,255,0.2);
}
.page-loading-box .glyphicon{
line-height: 100px;
animation-name: rotate360;
animation-timing-function: linear;
animation-iteration-count: infinite;
animation-direction: normal;
animation-duration: 1.4s;
}
.page-loading-text{
line-height: 100px;
position: absolute;
top: 0;
left: 0;
width: 100%;
height: 100%;
font-size: 14px;
color: #fff;
text-align: center;
}
.page-loading-text>span{
animation-timing-function: linear;
animation-iteration-count: infinite;
animation-direction: normal;
animation-duration: 2s;
}
.page-loading-text>span:nth-of-type(1){
animation-name: pointShine1;
}
.page-loading-text>span:nth-of-type(2){
animation-name: pointShine2;
}
.page-loading-text>span:nth-of-type(3){
animation-name: pointShine3;
}
@keyframes rotate360 {
0%{
transform: rotate(0);
}
50%{
transform: rotate(180deg);
}
100%{
transform: rotate(360deg);
}
}
@keyframes pointShine1 {
0% {
opacity: 0;
}
32% {
opacity: 1;
}
96% {
opacity: 1;
}
100% {
opacity: 0;
}
}
@keyframes pointShine2 {
0% {
opacity: 0;
}
32% {
opacity: 0;
}
64% {
opacity: 1;
}
96% {
opacity: 1;
}
100% {
opacity: 0;
}
}
@keyframes pointShine3 {
0% {
opacity: 0;
}
64% {
opacity: 0;
}
96% {
opacity: 1;
}
100% {
opacity: 0;
}
}
Code class
/** * loading Animation */
function Loading() {
this.loadings = [];
// this.loadingHtml = '<div class="page-loading">'
this.loadingHtml = '<div class="page-loading-div">'
+ '<div class="page-loading-box">'
+ '<i class="glyphicon glyphicon-refresh"></i>'
+ '<div class="page-loading-text"> Loading <span>.</span><span>.</span><span>.</span></div>'
+ '</div>'
+ '</div>'
// + '</div>';
}
Loading.prototype.doLoading = function(){
let code = Math.floor(Math.random() * 100000);
this.loadings.push(code);
let bodyDom = document.getElementsByTagName('body');
if(bodyDom.length > 0){
let childsDoms = bodyDom[0].childNodes;
let isInsert = false;
if(childsDoms && childsDoms.length > 0){
for(var i = 0; i< childsDoms.length; i++){
let childDom = childsDoms[i];
let className = childDom && childDom.className;
className = className != null && className != undefined ? className : '';
if(className.indexOf('page-loading') >= 0){
isInsert = true;
}
}
}
if(!isInsert){
var DIV = document.createElement("DIV");
DIV.className = 'page-loading';
DIV.innerHTML = this.loadingHtml;
bodyDom[0].appendChild(DIV);
}
}
return code;
}
Loading.prototype.removeLoadingDom = function() {
let bodyDom = document.getElementsByTagName('body');
if(bodyDom.length > 0){
let childsDoms = bodyDom[0].childNodes;
if(childsDoms && childsDoms.length > 0){
for(var i = 0; i< childsDoms.length; i++){
let childDom = childsDoms[i];
// console.log(childDom, childDom.className);
let className = childDom && childDom.className;
className = className != null && className != undefined ? className : '';
if(className.indexOf('page-loading') >= 0){
bodyDom[0].removeChild(childDom);
}
}
}
}
}
Loading.prototype.closeLoading = function(code){
let {
loadings } = this;
if(loadings && loadings.length > 0){
let index = loadings.indexOf(code);
if(index > -1){
loadings.splice(index, 1);
}
}
if(loadings && loadings.length == 0){
this.removeLoadingDom();
}
}
Loading.prototype.closeAllLoading = function() {
this.loadings = [];
this.removeLoadingDom();
}
Loading.prototype.getLoadings = function() {
let {
loadings } = this;
return loadings && loadings.length > 0 ? loadings : [];
}
Loading.prototype.checkIsInLoading = function(code){
let {
loadings } = this;
return loadings && loadings.length > 0 && loadings.indexOf(code) > -1;
}
Use
let loading = new Loading();
let loadCode = loading.doLoading();
setTimeout(function() {
loading.closeLoading(loadCode);
}, 2000)
effect
边栏推荐
- Mrs offline data analysis: process OBS data through Flink job
- 麒麟信安操作系统衍生产品解决方案 | 存储多路径管理系统,有效提高数据传输可靠性
- 责任链模式 - Unity
- Actionbar navigation bar learning
- 本周小贴士#136:无序容器
- LeetCode 497(C#)
- 【网络攻防原理与技术】第4章:网络扫描技术
- 【TPM2.0原理及应用指南】 12、13、14章
- Toast will display a simple prompt message on the program interface
- 本周小贴士#141:注意隐式转换到bool
猜你喜欢
Share the latest high-frequency Android interview questions, and take you to explore the Android event distribution mechanism
第3章业务功能开发(安全退出)
VSCode关于C语言的3个配置文件
Toast will display a simple prompt message on the program interface
麒麟信安云平台全新升级!
Mrs offline data analysis: process OBS data through Flink job
麒麟信安携异构融合云金融信创解决方案亮相第十五届湖南地区金融科技交流会
赋能智慧电力建设 | 麒麟信安高可用集群管理系统,保障用户关键业务连续性
请将磁盘插入“U盘(H)“的情况&无法访问 磁盘结构损坏且无法读取
企业即时通讯软件是什么?它有哪些优势呢?
随机推荐
DatePickerDialog和trimepickerDialog
让保险更“保险”!麒麟信安一云多芯云桌面中标中国人寿, 助力金融保险信息技术创新发展
【可信计算】第十二次课:TPM授权与会话
viewflipper的功能和用法
How to mount the original data disk without damage after the reinstallation of proxmox ve?
calendarview日历视图组件的功能和用法
运行yolo v5-5.0版本报错找不到SPPF错误,进行解决
【网络攻防原理与技术】第7章:口令攻击技术 第8章:网络监听技术
第3章业务功能开发(实现记住账号密码)
L1-028 判断素数(Lua)
redis主从、哨兵主备切换搭建一步一步图解实现
目标管理【管理学之十四】
本周小贴士#136:无序容器
【可信计算】第十一次课:TPM密码资源管理(三) NV索引与PCR
Functions and usage of tabhost tab
On Apache Doris Fe processing query SQL source code analysis
【重新理解通信模型】Reactor 模式在 Redis 和 Kafka 中的应用
[fan Tan] after the arrival of Web3.0, where should testers go? (ten predictions and suggestions)
Define menus using XML resource files
Functions and usage of ratingbar