码迷,mamicode.com
首页 > 其他好文 > 详细

百分百加载动画

时间:2017-01-20 16:28:43      阅读:305      评论:0      收藏:0      [点我收藏+]

标签:clear   images   false   sky   ges   doctype   begin   logs   arc   

技术分享

 



<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Title</title>
</head>
<body>
<canvas id="canvas" width="500" height="500">
您的浏览器不支持canvas
</canvas>
<script>
window.onload = function () {
var canvas = document.getElementById(‘canvas‘),
context = canvas.getContext(‘2d‘),
cirX = canvas.width/ 2,
cirY = canvas.height/ 2,
rad = Math.PI * 2 /100,
n = 1,
speed = 150,
r = 100;
//绘制最外层细圈
function writeCircle(){
context.save();
context.beginPath();
context.strokeStyle = ‘skyblue‘;
context.arc(cirX,cirY,r,0,Math.PI * 2,false);
context.stroke();
context.restore();
}
//绘制文本
function writeText(n){
context.save();
context.strokeStyle = ‘skyblue‘;
context.font = ‘40px Arial‘;
context.strokeText(n.toFixed(0)+‘%‘,cirX-30,cirY+10);
context.stroke();
context.restore();
}
//绘制蓝色外圈
function writeBlue(n){
context.save();
context.strokeStyle = ‘skyblue‘;
context.lineWidth = 4;
context.beginPath();
context.arc(cirX,cirY,r,-Math.PI/2,-Math.PI/2+rad*n,false);
context.stroke();
context.restore();
}

function DreamLoading(){
//清除所有,重新绘制
context.clearRect(0,0,canvas.width,canvas.height);
writeCircle();
writeText(n);
writeBlue(n);
if(n < 100){
n = n + 0.1;
}else{
n = 0;
}
requestAnimationFrame(DreamLoading);
}
DreamLoading();
}

</script>
</body>
</html>

百分百加载动画

标签:clear   images   false   sky   ges   doctype   begin   logs   arc   

原文地址:http://www.cnblogs.com/xzq1992/p/6322984.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!