通过定义一个canvas标签, new方法传进ID值,和旋转角度值,即可生成圆形进度条

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>圆进度条</title>
</head>
<body>
<canvas id="yuan" width="200" height="200"></canvas>
</body>
<script src="jquery-1.11.1.min.js"></script>
<script type="text/javascript">
window.chart =function(ID){
var canvas = document.getElementById(ID);
var ctx = canvas.getContext("2d");
// 画布宽高
var W = canvas.width;
var H = canvas.height;
//度角
var degrees = 0;
var new_degrees = 0;
// 差额
var difference = 0;
var text,text_w; // 文字
var R =W < H ? W:H; //先默认环半径为canvas宽度
var outW =parseInt(R / 14); //环宽度
var outR = (R/2) -outW; //环半径=canvas宽度半径 -外环宽度
var $this = this;
console.log("canvas宽度:"+R);
console.log(outW);
console.log(outR); $this.ratePieNoAnimation = function (number){
degrees =360*number/100; // 园弧底图
ctx.clearRect(0,0,W,H);//先清画布
ctx.beginPath();
ctx.strokeStyle ="green";
// 园弧线的宽度
ctx.lineWidth = outW;
ctx.arc(W / 2, H / 2, outR, 0, Math.PI * 2, false);
ctx.stroke(); //圆弧动画
var r = degrees * Math.PI / 180;
ctx.beginPath();
ctx.strokeStyle = "#994746";
ctx.lineWidth = outW;
// 弧将从最顶端开始
ctx.arc(W / 2, H / 2, outR, 0 - 90 * Math.PI / 180, r - 90 * Math.PI / 180, false);
ctx.stroke(); // 文字添加
ctx.fillStyle = "#63d2ef";
ctx.shadowColor = "#eee";
ctx.font = "bold " + R / 6 + "px hanyi";
text = Math.floor(degrees / 360 * 100) + "%";
text_w = ctx.measureText(text).width;
ctx.fillText(text, W / 2 - text_w / 2, H / 2 + R / 10);
}; $this.ratePie = function(number){
var i=0;
var time=setInterval(function(){
if( i==number){
clearInterval(time);
}else{
number >0 ? i++ : i--;
}
$this.ratePieNoAnimation(i);
if( i>100 || i<-100){
$this.ratePieNoAnimation(number);
clearInterval(time);
}
}, 2000 / (number > 0 ? number : -number));
}; } new chart("yuan").ratePie(50);
</script>
</html>

最新文章

  1. SQL Server 重新组织生成索引
  2. css元素排列
  3. BZOJ2408 混乱的置换
  4. SQL Server 2008 评估期已过解决方法
  5. C#和SQl 注入字符串的攻击 和 防止注入字符转的攻击
  6. 转:Linux 安装 Mysql
  7. java 编译中没有清除之前编译出来的文件。
  8. Oracle 学习用
  9. PPAS上运行pg_dump经过II
  10. 理解C#系列 / 结束
  11. UVA 10529-Dumb Bones(概率dp)
  12. This Android SDK requires Android Developer Toolkit version 23.0.0 or above
  13. 大众点评网王宏:从.Net迁移向Java平台 - 51CTO.COM
  14. JS获取当前日期时间并定时刷新
  15. SuperWebClient -一个基于CURL的.NET HTTP/HTTPS模拟神组件(2)
  16. Yii2基本概念之——属性(property)
  17. UTC时间戳转为时间
  18. C#_02.14_基础五_.NET类
  19. HTML 点击图片放大
  20. Linux服务器---邮件服务openwebmail安装

热门文章

  1. Backbone之旅——Collection and View篇
  2. [Z] 计算机类会议期刊根据引用数排名
  3. ios 关于文件操作 获取 文件大小
  4. asp.net MVC之 自定义过滤器(Filter)
  5. Codeforces Round #197 (Div. 2) (A、B、C、D、E五题合集)
  6. CGContext 的一些工具方法
  7. SNF开发平台WinForm之一-开发-单表表格编辑管理页面-SNF快速开发平台3.3-Spring.Net.Framework
  8. MyBatis 入门
  9. Uvaoj 11248 Frequency Hopping(Dinic求最小割)
  10. ubuntu14.04编译安装Git2.7