当前位置:网站首页>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
边栏推荐
- 在窗口上面显示进度条
- [fan Tan] those stories that seem to be thinking of the company but are actually very selfish (I: building wheels)
- Solid function learning
- PLC: automatically correct the data set noise, wash the data set | ICLR 2021 spotlight
- Linux 安装mysql8.X超详细图文教程
- 请将磁盘插入“U盘(H)“的情况&无法访问 磁盘结构损坏且无法读取
- 【信息安全法律法规】复习篇
- 无法链接远程redis服务器(解决办法百分百)
- 【可信计算】第十三次课:TPM扩展授权与密钥管理
- 《世界粮食安全和营养状况》报告发布:2021年全球饥饿人口增至8.28亿
猜你喜欢
【TPM2.0原理及应用指南】 12、13、14章
让保险更“保险”!麒麟信安一云多芯云桌面中标中国人寿, 助力金融保险信息技术创新发展
网络攻防复习篇
【OKR目标管理】案例分析
Share the latest high-frequency Android interview questions, and take you to explore the Android event distribution mechanism
百度地图自定义样式向右拖拽导致全球地图经度0度无法正常显示
DatePickerDialog and trimepickerdialog
鲲鹏开发者峰会2022 | 麒麟信安携手鲲鹏共筑计算产业新生态
策略模式 - Unity
toast会在程序界面上显示一个简单的提示信息
随机推荐
【可信计算】第十三次课:TPM扩展授权与密钥管理
[source code interpretation] | source code interpretation of livelistenerbus
How to mount the original data disk without damage after the reinstallation of proxmox ve?
PLC: automatically correct the data set noise, wash the data set | ICLR 2021 spotlight
Audio Device Strategy 音频设备输出、输入 选择 基于7.0 代码
MySQL usage notes 1
【TPM2.0原理及应用指南】 1-3章
datepicket和timepicket,日期、时间选择器的功能和用法
如何在软件研发阶段落地安全实践
2021-06-28
【网络攻防原理与技术】第5章:拒绝服务攻击
Show progress bar above window
Function and usage of textswitch text switcher
L1-019 谁先倒(Lua)
[fan Tan] those stories that seem to be thinking of the company but are actually very selfish (I: building wheels)
LeetCode 497(C#)
深入浅出【机器学习之线性回归】
使用popupwindow創建对话框风格的窗口
第2章搭建CRM项目开发环境(搭建开发环境)
Is AI more fair than people in the distribution of wealth? Research on multiplayer game from deepmind