js预加载loading的canvas写法(无图片)。

页面html:

<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>不需要页面图片显示加载</title>
<style>
   html{
    background: gray;
   }
   #loading{
   z-index: 200;
   position: fixed;
   top: 50%;
   left: 50%;
   border:1px solid red;
}
#loading-screen {
   display: block;
   position: absolute;
   text-align: center;
   width: 60px;
   height: 60px;
   top: 50%;
   -webkit-transform: translate(-50%,-50%);
   transform: translate(-50%,-50%);
   left: 50%;
   background: white;
   border-radius: 5px;
   z-index: 500;
}
#canvas-font-wrap{
font-family: '微软雅黑';
position:relative;
height: 60px;
width:60px;
line-height: 60px;
text-align: center;
color: darkgray;
}
.font-center{
height: 48px;
width:48px;
border:2px solid rgb(223,223,223);
border-radius: 25px;
line-height:48px;
position: absolute;
left: 4px;
top:4px;
}

#loading-screen .vip-cvs {
   position: absolute;
   left: 0;
   top: 0;
   -webkit-transform: translate(-25%,-25%) scale(0.5);
   transform: translate(-25%,-25%) scale(0.5);
}


</style>
</head>
<body>
<div id="loading">
   <div id='loading-screen'>
    <div id="canvas-font-wrap"style="">
    <div class="font-center" style="">cpp</div>
    </div>
       <canvas class='vip-cvs' width='120' height='120' id="canvas"></canvas>
   </div>
</div>
<!--//js路径更改自己的路径-->
<script type="text/javascript" src="../js/jquery.min.js" ></script>
<!--js路径更改自己的路径-->
<script type="text/javascript" src="../js/loadAnimation.js" ></script>
<script type="text/javascript">
showLoadingScreen();
</script>
</body>
</html>

页面加载打圈的js写法:

/**
 * Created by chenxiaopeng on 2016/10/13.
 */
var loadingHandel = null;
function initLoadingAnimate() {
    var step = 0;
    var bg = $('.vip-cvs')[0];
    var ctx = bg.getContext('2d');
    var imd = null;
    var circ = Math.PI * 2;
    var quart = Math.PI / 2;
    var lineColor = '#e5007f';
    var backforward = true;


    ctx.clearRect(0, 0, 120, 120);
    ctx.beginPath();
    ctx.strokeStyle = lineColor;
    ctx.lineCap = 'square';
    ctx.closePath();
    ctx.fill();
    ctx.lineWidth = 2.8;
    imd = ctx.getImageData(0, 0, 120, 120);
    
    var draw = function(current) {
        ctx.putImageData(imd,0,0,0,0,120,120);
        ctx.beginPath();
        ctx.arc(60, 60, 50, -(quart), ((circ) * current) - quart, backforward);
        ctx.stroke();
    }


    function stepDraw() {
    //draw(0.5);
        step += 0.01;
        draw(step);
        if (step >= 0.99) {
            step = 0;
            if (!backforward) {
                backforward = true;
            } else {
                backforward = false;
            }
        }
    }


    loadingHandel = setInterval(stepDraw, 10);
}


function clearLoadingAnimation() {
    clearInterval(loadingHandel);
}


function showLoadingScreen() {
    initLoadingAnimate();
    $('#loading').show();
}


function hideLoadingScreen() {
    clearLoadingAnimation();
    $('#loading').hide();

}


//需要引进jquery,整个页面没有图片,很棒。

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值