当前位置:网站首页>简单的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)
效果
边栏推荐
- PLC:自动纠正数据集噪声,来洗洗数据集吧 | ICLR 2021 Spotlight
- LeetCode 1155. N ways to roll dice one question per day
- User defined view essential knowledge, Android R & D post must ask 30+ advanced interview questions
- Reflections on "product managers must read: five classic innovative thinking models"
- mysql官网下载:Linux的mysql8.x版本(图文详解)
- 【可信计算】第十二次课:TPM授权与会话
- 状态模式 - Unity(有限状态机)
- Sator a lancé le jeu web 3 "satorspace" et a lancé huobi
- LeetCode 403. Frog crossing the river daily
- 专精特新软件开发类企业实力指数发布,麒麟信安荣誉登榜
猜你喜欢
Sator推出Web3游戏“Satorspace” ,并上线Huobi
如何在博客中添加Aplayer音乐播放器
麒麟信安携异构融合云金融信创解决方案亮相第十五届湖南地区金融科技交流会
管理VDI的几个最佳实践
麒麟信安操作系统衍生产品解决方案 | 存储多路径管理系统,有效提高数据传输可靠性
【TPM2.0原理及应用指南】 16、17、18章
SlashData开发者工具榜首等你而定!!!
企业即时通讯软件是什么?它有哪些优势呢?
DevOps 的运营和商业利益指南
Skimage learning (3) -- adapt the gray filter to RGB images, separate colors by immunohistochemical staining, and filter the maximum value of the region
随机推荐
DevOps 的运营和商业利益指南
责任链模式 - Unity
无法链接远程redis服务器(解决办法百分百)
Establishment of solid development environment
Number of exchanges in the 9th Blue Bridge Cup finals
mysql官网下载:Linux的mysql8.x版本(图文详解)
【TPM2.0原理及应用指南】 16、17、18章
[Huang ah code] Why do I suggest you choose go instead of PHP?
本周小贴士#141:注意隐式转换到bool
LeetCode 1031. Maximum sum of two non overlapping subarrays
Blue Bridge Cup final XOR conversion 100 points
Skimage learning (2) -- RGB to grayscale, RGB to HSV, histogram matching
SlashData开发者工具榜首等你而定!!!
Repair method of firewall system crash and file loss, material cost 0 yuan
LeetCode 1477. Find two subarrays with sum as the target value and no overlap
First in China! Todesk integrates RTC technology into remote desktop, with clearer image quality and smoother operation
mysql使用笔记一
【饭谈】那些看似为公司着想,实际却很自私的故事 (一:造轮子)
Solidity 开发环境搭建
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?