首页 > 代码库 > 百分百加载动画
百分百加载动画
<!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>
百分百加载动画
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。