<!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. 最小生成树 HDU1301 (kuskal & prim)

    Kruskal:1.边排序,2.按边从小到大连接森林至树   3.并查集 #include <stdio.h> #include <stdlib.h> #include < ...

  2. # -*- coding: utf-8 -*-

    -- coding: utf-8 -- import scrapy from jobscrawler_qianchengwuyou.items import JobscrawlerQianchengw ...

  3. 谷歌排名影响因素最新研究(SEM RUSH版)

    谷歌排名影响因素,关于这块的研究在国外有很多,一全老师(www.yiquanseo.com)以前也专门翻译整合过两篇,分别是Backlinko的<谷歌排名影响因素权威报告(研究了数百万谷歌网站得 ...

  4. 有时候union或者union all比左连接查询速度快

    原来的语句 select count(1) from  ( SELECT CustCode,ShopCode,CreateTime,UniqCode,SaleType,TotalMoney,Exami ...

  5. leetcode日记 HouseRobber I II

    House Robber I You are a professional robber planning to rob houses along a street. Each house has a ...

  6. 对弈win32笔记

    对弈的win32笔记   一:Windows程序运行原理 一.Windows四大模块程序 1.1控制台程序 没有自己的窗口,dos-显示或者运行程序,入口mian() 1.2窗口程序 有自己的窗口,w ...

  7. DevExpress v18.2版本亮点——Reporting篇(三)

    行业领先的.NET界面控件——DevExpress v18.2日前正式发布,本站将以连载的形式为大家介绍新版本新功能.本文将介绍了DevExpress Reporting v18.2 的新功能,新版3 ...

  8. c++错误

    run-time check failure #2-stack around the variable 'c' was corrupted错误产生的原因大多是因为程序定义了数组,存在数组越界.解决办法 ...

  9. windows mysql 和linux mysql解决乱码问题

    windows : 1找到mysql安装目录的my.ini文件 2修改的里面的内容为 character-set-server=utf8 default-character-set=UTF-8 然后打 ...

  10. java集合(二)