当前位置:网站首页>简单的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)
效果

边栏推荐
- [video / audio data processing] Shanghai daoning brings you elecard download, trial and tutorial
- 【可信计算】第十次课:TPM密码资源管理(二)
- The top of slashdata developer tool is up to you!!!
- 状态模式 - Unity(有限状态机)
- [Seaborn] combination chart: facetgrid, jointgrid, pairgrid
- From Devops to mlops: how do it tools evolve to AI tools?
- SlashData开发者工具榜首等你而定!!!
- Devops' operational and commercial benefits Guide
- 本周小贴士131:特殊成员函数和`= default`
- Mrs offline data analysis: process OBS data through Flink job
猜你喜欢

网络攻防复习篇

How to add aplayer music player in blog

【信息安全法律法规】复习篇

Is AI more fair than people in the distribution of wealth? Research on multiplayer game from deepmind

策略模式 - Unity

【TPM2.0原理及应用指南】 9、10、11章

How to choose the appropriate automated testing tools?

SIGGRAPH 2022最佳技术论文奖重磅出炉!北大陈宝权团队获荣誉提名

麒麟信安云平台全新升级!

Biped robot controlled by Arduino
随机推荐
How to add aplayer music player in blog
LeetCode 1981. Minimize the difference between the target value and the selected element one question per day
本周小贴士#134:make_unique与私有构造函数
Flash build API Service - generate API documents
DNS 系列(一):为什么更新了 DNS 记录不生效?
Sator推出Web3遊戲“Satorspace” ,並上線Huobi
Blue Bridge Cup final XOR conversion 100 points
mysql实现两个字段合并成一个字段查询
麒麟信安携异构融合云金融信创解决方案亮相第十五届湖南地区金融科技交流会
Skimage learning (1)
Devops' operational and commercial benefits Guide
Flask搭建api服务-SQL配置文件
【饭谈】Web3.0到来后,测试人员该何去何从?(十条预言和建议)
服务器彻底坏了,无法修复,如何利用备份无损恢复成虚拟机?
PLC: automatically correct the data set noise, wash the data set | ICLR 2021 spotlight
LeetCode 535(C#)
MySQL implements the query of merging two fields into one field
大笨钟(Lua)
How to choose the appropriate automated testing tools?
【TPM2.0原理及应用指南】 12、13、14章