当前位置:网站首页>简单的loading动画
简单的loading动画
2022-07-07 15:40:00 【梓喻】
样式
.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;
}
}
代码类
/** * loading动画 */
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">加载中<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;
}
使用
let loading = new Loading();
let loadCode = loading.doLoading();
setTimeout(function() {
loading.closeLoading(loadCode);
}, 2000)
效果

边栏推荐
- 【源码解读】| LiveListenerBus源码解读
- LeetCode 1626. The best team without contradiction
- 【网络攻防原理与技术】第3章:网络侦察技术
- [source code interpretation] | source code interpretation of livelistenerbus
- Solid function learning
- 【信息安全法律法規】複習篇
- PLC:自动纠正数据集噪声,来洗洗数据集吧 | ICLR 2021 Spotlight
- Devops' operational and commercial benefits Guide
- MRS离线数据分析:通过Flink作业处理OBS数据
- The server is completely broken and cannot be repaired. How to use backup to restore it into a virtual machine without damage?
猜你喜欢

How to add aplayer music player in blog

管理VDI的几个最佳实践

The top of slashdata developer tool is up to you!!!

99%的人都不知道|私有化部署还永久免费的即时通讯软件!

状态模式 - Unity(有限状态机)

Sator推出Web3游戏“Satorspace” ,并上线Huobi

【可信计算】第十三次课:TPM扩展授权与密钥管理

Mrs offline data analysis: process OBS data through Flink job

Skimage learning (1)

Linux 安装mysql8.X超详细图文教程
随机推荐
【饭谈】那些看似为公司着想,实际却很自私的故事 (一:造轮子)
【黄啊码】为什么我建议您选择go,而不选择php?
Several best practices for managing VDI
Skimage learning (2) -- RGB to grayscale, RGB to HSV, histogram matching
麒麟信安云平台全新升级!
邮件服务器被列入黑名单,如何快速解封?
鲲鹏开发者峰会2022 | 麒麟信安携手鲲鹏共筑计算产业新生态
LeetCode 403. Frog crossing the river daily
本周小贴士#136:无序容器
本周小贴士#141:注意隐式转换到bool
如何在博客中添加Aplayer音乐播放器
How to implement safety practice in software development stage
The computer cannot add a domain, and the Ping domain name is displayed as the public IP. What is the problem? How to solve it?
企业即时通讯软件是什么?它有哪些优势呢?
DevOps 的运营和商业利益指南
[fan Tan] after the arrival of Web3.0, where should testers go? (ten predictions and suggestions)
LeetCode 1626. The best team without contradiction
Solid function learning
Nerf: the ultimate replacement for deepfake?
Repair method of firewall system crash and file loss, material cost 0 yuan