html页面加载时出现动态效果

在<head></head>里面引入以下代码

 <!-- 加载画面 -->
	<link rel="stylesheet" href="../static/css/loading.css">
    <script src="../static/js/loading.js"></script>

loading.css

.spinner {
    width: 60px;
    height: 60px;
    background-image: linear-gradient(0deg,#8a76f6,#70cafe);
   
    margin: 100px auto;
    -webkit-animation: rotateplane 1.2s infinite ease-in-out;
    animation: rotateplane 1.2s infinite ease-in-out;
    
  }
   
  @-webkit-keyframes rotateplane {
    0% { -webkit-transform: perspective(120px) }
    50% { -webkit-transform: perspective(120px) rotateY(180deg) }
    100% { -webkit-transform: perspective(120px) rotateY(180deg)  rotateX(180deg) }
  }
   
  @keyframes rotateplane {
    0% {
      transform: perspective(120px) rotateX(0deg) rotateY(0deg);
      -webkit-transform: perspective(120px) rotateX(0deg) rotateY(0deg)
    } 50% {
      transform: perspective(120px) rotateX(-180.1deg) rotateY(0deg);
      -webkit-transform: perspective(120px) rotateX(-180.1deg) rotateY(0deg)
    } 100% {
      transform: perspective(120px) rotateX(-180deg) rotateY(-179.9deg);
      -webkit-transform: perspective(120px) rotateX(-180deg) rotateY(-179.9deg);
    }
  }

loading.js

//获取浏览器页面可见高度和宽度  
var _PageHeight = document.documentElement.clientHeight,  
_PageWidth = document.documentElement.clientWidth;  
//计算loading框距离顶部和左部的距离(loading框的宽度为215px,高度为61px)  
var _LoadingTop = _PageHeight > 90 ? (_PageHeight - 90) / 2 : 0,  
_LoadingLeft = _PageWidth > 90 ? (_PageWidth - 90) / 2 : 0;  
//在页面未加载完毕之前显示的loading Html自定义内容  
var _LoadingHtml = '<div id="loadingDiv" style="position:absolute;left:0;width:100%;height:' + _PageHeight + 'px;top:0;background:#FFFFFF;opacity:1.0;filter:alpha(opacity=80);z-index:10000;"><div class="spinner" style="position: top: 60px; margin:' + _LoadingTop + 'px auto ;"></div></div>';  
//呈现loading效果  
document.write(_LoadingHtml);  

//监听加载状态改变  
document.onreadystatechange = completeLoading;  

//加载状态为complete时移除loading效果  
function completeLoading() {  
if (document.readyState == "complete") {  
$("#loadingDiv").fadeOut(1500);
}  
}  

参考链接:

html页面Loading效果实现:加载新页面前的等待过渡画面 - 编程猎人

  • 1
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值