<!DOCTYPE html>
<html >
<head>
<meta http-equiv="content-type" content="text/html" charset="utf-8">
<meta name="author" content="xuyunfei">
<meta name="description" content="">
<meta name="keywords" content="test,html">
<title>环形进度条</title>
</head>
<body>
</br></br></br></br> <div style="width:300px; height:300px; margin:20px auto">
<canvas id="canvas" width="300" height="300">
<p>抱歉,您的浏览器不支持canvas</p>
</canvas>
</div> <script type="text/javascript">
function toCanvas(id ,progress){
// canvas进度条
var canvas = document.getElementById(id),
ctx = canvas.getContext("2d"),
percent = progress, //最终百分比
circleX = canvas.width / 2, //中心x坐标
circleY = canvas.height / 2, //中心y坐标
radius = 100, //圆环半径
lineWidth = 5, //圆形线条的宽度
fontSize = 20; //字体大小
//两端圆点
// function smallcircle1(cx, cy, r) {
// ctx.beginPath();
// //ctx.moveTo(cx + r, cy);
// ctx.lineWidth = 1;
// ctx.fillStyle = '#06a8f3';
// ctx.arc(cx, cy, r,0,Math.PI*2);
// ctx.fill();
// }
// function smallcircle2(cx, cy, r) {
// ctx.beginPath();
// //ctx.moveTo(cx + r, cy);
// ctx.lineWidth = 1;
// ctx.fillStyle = '#00f8bb';
// ctx.arc(cx, cy, r,0,Math.PI*2);
// ctx.fill();
// } //画圆
function circle(cx, cy, r) {
ctx.beginPath();
//ctx.moveTo(cx + r, cy);
ctx.lineWidth = lineWidth;
ctx.strokeStyle = '#eee';
ctx.arc(cx, cy, r, 0, (Math.PI*2),true);
ctx.stroke();
} //画弧线
function sector(cx, cy, r, startAngle, endAngle, anti) {
ctx.beginPath();
//ctx.moveTo(cx, cy + r); // 从圆形底部开始画
ctx.lineWidth = lineWidth; // 渐变色 - 可自定义
// var linGrad = ctx.createLinearGradient(
// circleX-radius-lineWidth, circleY, circleX+radius+lineWidth, circleY
// );
// linGrad.addColorStop(0.0, '#06a8f3');
//linGrad.addColorStop(0.5, '#9bc4eb');
// linGrad.addColorStop(1.0, '#00f8bb');
// ctx.strokeStyle = linGrad;
ctx.strokeStyle = 'red'; //圆弧两端的样式
ctx.lineCap = 'round'; //圆弧
// ctx.arc(
// cx, cy, r,
// -1.5,
// -1.5 + endAngle/100 * (Math.PI*5/3),
// false
// );
ctx.arc(
cx, cy, r,
(Math.PI*-1/2),
(Math.PI*-1/2) + endAngle/100 * (Math.PI*2),
false
);
ctx.stroke();
} //刷新
function loading() {
if (process >= percent) {
// clearInterval(circleLoading);
process = 0.0;
} //清除canvas内容
ctx.clearRect(0, 0, circleX * 2, circleY * 2); //中间的字
ctx.font = fontSize + 'px April';
ctx.textAlign = 'center';
ctx.textBaseline = 'middle';
ctx.fillStyle = '#999';
ctx.fillText(parseFloat(process).toFixed(0) + '%', circleX, circleY); //圆形
circle(circleX, circleY, radius); //圆弧
sector(circleX, circleY, radius, (Math.PI*-1/2), process);
//两端圆点
// smallcircle1(150+Math.cos(2*Math.PI/360*120)*100, 150+Math.sin(2*Math.PI/360*120)*100, 5);
// smallcircle2(150+Math.cos(2*Math.PI/360*(120+process*3))*100, 150+Math.sin(2*Math.PI/360*(120+process*3))*100, 5);
//控制结束时动画的速度
// if (process / percent > 0.90) {
// process += 0.30;
// } else if (process / percent > 0.80) {
// process += 0.55;
// } else if (process / percent > 0.70) {
// process += 0.75;
// } else {
process += 1.0;
// }
} var process = 0.0; //进度
var circleLoading = window.setInterval(function () {
loading();
}, 1000); } //第二部分,调用封装好的代码:
toCanvas('canvas',100); </script>
</body>
</html>

canvas绘制环形进度条的更多相关文章

  1. html5 canvas绘制环形进度条,环形渐变色仪表图

    html5 canvas绘制环形进度条,环形渐变色仪表图                                             在绘制圆环前,我们需要知道canvas arc() 方 ...

  2. canvas 绘制环形进度条

    结果: 代码: <!DOCTYPE html> <html> <head lang="en"> <meta charset="U ...

  3. canvas绘制圆形进度条(或显示当前已浏览网页百分比)

    使用canvas绘制圆形进度条,或者是网页加载进度条 或者是显示你浏览了本网页多少-- 由于个浏览器的计算差异,打开浏览器时 初始值有所不同,但是当拉倒网页底部时,均显示100%. 兼容性:测试浏览器 ...

  4. Canvas实现环形进度条

    Canvas实现环形进度条 直接上代码: <canvas width="200" height="200" >60%</canvas> ...

  5. canvas 绘制圆形进度条

    <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...

  6. 使用canvas实现环形进度条

    html代码: <!DOCTYPE html> <html> <head> <meta charset="utf-8" /> < ...

  7. CSS3绘制环形进度条

    <!DOCTYPE html> <html> <head lang="en"> <meta charset="UTF-8&quo ...

  8. canvas环形进度条

    <style> canvas { border: 1px solid red; margin: 100px; }</style> <canvas id="rin ...

  9. iOS带动画的环形进度条(进度条和数字同步)

    本篇写的是实现环形进度条,并带动画效果,要实现这些,仅能通过自己画一个 方法直接看代码 为了方便多次调用,用继承UIView的方式 .m文件 #import <UIKit/UIKit.h> ...

随机推荐

  1. 使用idea启动springMVC+Hibernate其他项目

    打开项目后打开Project Structure 点开左边的Libraries 加入依赖包 点开左边的Moudules 选中项目 新建Web,Spring,Hibernate三项 Hibernate添 ...

  2. 在win系统安装Git

    Git是优秀, 先进的代码版本控制管理工具, 是分布式, 比SVN进步. 比如我们可以从Github拉取代码, 或者上传到GIthub. 下面说下安装: 搜索引擎搜索Git, 找到官网, 找到安装文件 ...

  3. LeetCode 148 排序链表

    题目: 在 O(n log n) 时间复杂度和常数级空间复杂度下,对链表进行排序. 示例 1: 输入: 4->2->1->3 输出: 1->2->3->4 示例 2 ...

  4. CPU-bound(计算密集型) 和I/O bound(I/O密集型) 区别 与应用

    I/O密集型 (CPU-bound) I/O bound 指的是系统的CPU效能相对硬盘/内存的效能要好很多,此时,系统运作,大部分的状况是 CPU 在等 I/O (硬盘/内存) 的读/写,此时 CP ...

  5. 本地pip 源搭建起来

    pip install pip2pi pip2tgz target_dir -r requirement.txt 下载想要的本地的py包  /usr/local/python3/bin/dir2pi ...

  6. .net 服务因为GC时遇到的问题和解决办法

    1.问题: .net单一服务中,大量的请求访问后台服务,多线程处理请求,但每个线程都可能出现超时的现象.记录超时日志显示,超时可能在序列化时,Socket异步发送AsyncSend数据时,普通业务处理 ...

  7. centos7 十万并发 关健配置

    vim /etc/sysctl.conf,添加 --开机启动加载内核参数:fs.file-max = 65535kernel.sem=250 32000 100 128 /proc/sys/kerne ...

  8. BUAAOO P5-P7 Elevator Simulation

    目录 Abstract Introduction Topic Request Elevator Analysis Reading Requests Coordinating Scheduling an ...

  9. 继承 in her it

    ''' in her it 继承 de rive 派生 python2 (经典类|新式类) python3 (新式类) 1. What is inheritance? 什么是继承? 继承是一种新建类的 ...

  10. 按照不规则多边形shp文件分割底层栅格文件tif,统计不同栅格的属性值

    我想做到,按照voronoi多边形分割地图土地利用类型文件,统计每个多边形内不同地物的种类和数量.-----如图: 我的第一个想法是:首先用上层多边形将下层栅格图切割开来,然后就可以分别统计栅格内的地 ...