html部分

<canvas id="canvas" width="150" height="150">
<p>抱歉,您的浏览器不支持canvas</p>
</canvas>

js部分

toCanvas('canvas','red',30);

    /**
* 生成环形进度条
*/
function toCanvas(id, color, progress) {
//canvas进度条
var canvas = document.getElementById(id),
ctx = canvas.getContext("2d"),
percent = progress, //最终百分比
circleX = canvas.width / 2, //中心x坐标
circleY = canvas.height / 2, //中心y坐标
radius = 60, //圆环半径
cradius = 75, // canvas半径
lineWidth = 6, //圆形线条的宽度
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 = '#fff';
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, Math.PI * 2 / 3, Math.PI * 1 / 3);
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 = color;
//圆弧两端的样式
ctx.lineCap = 'round'; //圆弧
ctx.arc(
cx, cy, r,
(Math.PI * 2 / 3),
(Math.PI * 2 / 3) + endAngle / 100 * (Math.PI * 5 / 3),
false
);
ctx.stroke();
} //刷新
function loading() {
if (process >= percent) {
clearInterval(circleLoading);
} //清除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 * 2 / 3, process);
//两端圆点
smallcircle1(cradius + Math.cos(2 * Math.PI / 360 * 120) * radius, cradius + Math.sin(2 * Math.PI / 360 * 120) *
radius, 0);
smallcircle2(cradius + Math.cos(2 * Math.PI / 360 * (120 + process * 3)) * radius, cradius + Math.sin(2 * Math.PI /
360 * (120 + process * 3)) * radius, 2);
//控制结束时动画的速度
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();
}, 20); }

canvas实现半圆环形进度条的更多相关文章

  1. 环形进度条的实现方法总结和动态时钟绘制(CSS3、SVG、Canvas)

    缘由: 在某一个游戏公司的笔试中,最后一道大题是,“用CSS3实现根据动态显示时间和环形进度[效果如下图所示],且每个圆环的颜色不一样,不需要考虑IE6~8的兼容性”.当时第一想法是用SVG,因为SV ...

  2. canvas绘制环形进度条

    <!DOCTYPE html> <html > <head> <meta http-equiv="content-type" conten ...

  3. canvas环形进度条

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

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

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

  5. Canvas实现环形进度条

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

  6. 用初中数学知识撸一个canvas环形进度条

    周末好,今天给大家带来一款接地气的环形进度条组件vue-awesome-progress.近日被设计小姐姐要求实现这么一个环形进度条效果,大体由四部分组成,分别是底色圆环,进度弧,环内文字,进度圆点. ...

  7. 【css】如何实现环形进度条

    最近团队的童鞋接到了一个有关环形进度条的需求,想要还原一个native的沿环轨迹渐变进度条的效果,看到这个效果的时候,笔者陷入了沉思.. 环形进度条的效果,最先想到的就是使用CSS利用两个半圆的hac ...

  8. 图解CSS3制作圆环形进度条的实例教程

    圆环形进度条制作的基本思想还是画出基本的弧线图形,然后CSS3中我们可以控制其旋转来串联基本图形,制造出部分消失的效果,下面就来带大家学习图解CSS3制作圆环形进度条的实例教程 首先,当有人说你能不能 ...

  9. 【CSS】环形进度条

    效果图 原理剖析 1.先完成这样一个半圆(这个很简单吧) 2.overflow: hidden; 3.在中间定位一个白色的圆形做遮挡 4.完成另一半 5.使用animate配合时间完成衔接 源码 &l ...

随机推荐

  1. Stage3--Python控制流程及函数

    说在前面: Stage1-Stage4简单介绍一下Python语法,Stage5开始用python实现一些实际应用,语法的东西到处可以查看到,学习一门程序语言的最终目的是应用,而不是学习语法,语法本事 ...

  2. SharePoint 2013 - Designer Workflow

    另一篇文章 SharePoint Designer - Workflow 1. 可以定义每个Stage的名称,并将Stage名称显示在工作流状态字段,相比于SP2010时仅有的in progress ...

  3. android 调试卡在:Waiting for Debugger - Application XXX is waiting for the debugger to Attach" 解决方法

    解决方法:重启adb. 步骤:cmd进入命令行,进入adb所在目录先后执行adb kill-server,adb start-server.

  4. HTML 5网页设计入门必读(书)

    今天看了一本由人民邮电出版社出版.邢薇薇 郭俊飞 王雪翻译的<HTML 5网页设计入门必读>,在此整理一下知识点,以及写一些自己的读后感. 本书的开章还是和大部分HTML 5书籍一样,用极 ...

  5. how reset smartphone data.

    question:how  reset  meizu smartphone solution one:hard step 1. power off your MEIZU smartphone. ste ...

  6. MySQL的基础(优化)2

    1.应尽量避免在 where 子句中使用!=或<>操作符,否则将引擎放弃使用索引而进行全表扫描. 2.对查询进行优化,应尽量避免全表扫描,首先应考虑在 where 及 order by 涉 ...

  7. web中的cookie管理

    本篇是以JSP为背景介绍,但是在web开发中也是相同的原理. 什么是cookie 由于http是一种无状态的协议,因此服务器收到请求后,只会当做一次新的请求.即便你重复发送了1000次同样的请求,这1 ...

  8. SAP S4CRM 1811 服务订单API介绍

    Jerry在今年2月28日,SAP Customer Management for S/4HANA 1.0正式问世这个具有纪念意义的日子,同时发布了中英文版的博客进行介绍. 英文版发在SAP社区上,至 ...

  9. python_列表/元组/元组列表以及如何使用

    1.list是处理一组有序项目的数据结构 #定义一个列表 list=[1,2,3] print type(list) print list[0] 输出: <type 'list'> 1 2 ...

  10. bash shell脚本之查看系统环境变量

    查看当前系统环境变量 cat test2: #!/bin/bash # display user information from the system. echo "User info f ...