canvas环形进度条
<style>
canvas {
border: 1px solid red;
margin: 100px;
}
</style>
<canvas id="ring-process-bar" width="100" height="100">
您的浏览器不支持html5 canvas标签。
</canvas>
<script>
var ring = document.getElementById('ring-process-bar');
var rtx = ring.getContext('2d');
rtx.beginPath(); //起始一条路径
rtx.lineWidth = 20; //设置当前线条的宽度
rtx.strokeStyle = '#ccc'; //设置笔触的颜色
rtx.lineCap = 'round'; //结束线帽:butt默认平直/round圆形/square正方形
rtx.arc(50, 50, 40, 0, 2 * Math.PI, true); //arc(x,y,r,start,stop,false) 创建弧/曲线/圆;圆中心点的x,y坐标;r半径;start起始角,三点钟位置为0度;false顺时针,默认
rtx.stroke();
</script>
<canvas id="ring-canvas" width="500" height="200">
您的浏览器不支持html5 canvas标签。
</canvas>
<script>
function Circle() {
this.centerX = 100;
this.centerY = 100;
this.radius = 90;
this.lineWidth = 20;
this.strokeStyle = '#ccc';
this.fillStyle = 'blue';
this.lineCap = 'round';
}
Circle.prototype.draw = function(ctx) {
ctx.beginPath();
ctx.arc(this.centerX, this.centerY, this.radius, 0, Math.PI * 2, false);
ctx.lineWidth = this.lineWidth;
ctx.strokeStyle = this.strokeStyle;
ctx.stroke();
};
function Ring(startAngle, percent) {
Circle.call(this);
this.startAngle = startAngle || Math.PI / 2 * 3; //弧起始角度
this.percent = percent; //弧占的比例
}
Ring.prototype = Object.create(Circle.prototype);
Ring.prototype.drawRing = function(ctx) {
var count = 0,
start = this.startAngle,
stop = start + Math.PI * 2 * this.percent / 100;
this.draw(ctx);
ctx.beginPath();
ctx.arc(this.centerX, this.centerY, this.radius, start, stop, false); //这里的圆心坐标要和cirle的保持一致
ctx.strokeStyle = this.fillStyle;
ctx.lineCap = this.lineCap;
ctx.stroke();
ctx.closePath();
}
var ring = document.getElementById('ring-canvas');
var rtx = ring.getContext('2d');
var r = new Ring(0, 80);
r.drawRing(rtx)
</script>
canvas环形进度条的更多相关文章
- 用初中数学知识撸一个canvas环形进度条
周末好,今天给大家带来一款接地气的环形进度条组件vue-awesome-progress.近日被设计小姐姐要求实现这么一个环形进度条效果,大体由四部分组成,分别是底色圆环,进度弧,环内文字,进度圆点. ...
- 环形进度条的实现方法总结和动态时钟绘制(CSS3、SVG、Canvas)
缘由: 在某一个游戏公司的笔试中,最后一道大题是,“用CSS3实现根据动态显示时间和环形进度[效果如下图所示],且每个圆环的颜色不一样,不需要考虑IE6~8的兼容性”.当时第一想法是用SVG,因为SV ...
- canvas绘制环形进度条
<!DOCTYPE html> <html > <head> <meta http-equiv="content-type" conten ...
- html5 canvas绘制环形进度条,环形渐变色仪表图
html5 canvas绘制环形进度条,环形渐变色仪表图 在绘制圆环前,我们需要知道canvas arc() 方 ...
- canvas实现半圆环形进度条
html部分 <canvas id="canvas" width="150" height="150"> <p>抱歉 ...
- Canvas实现环形进度条
Canvas实现环形进度条 直接上代码: <canvas width="200" height="200" >60%</canvas> ...
- 仿MIUI音量变化环形进度条实现
Android中使用环形进度条的业务场景事实上蛮多的,比方下载文件的时候使用环形进度条.会给用户眼前一亮的感觉:再比方我大爱的MIUI系统,它的音量进度条就是使用环形进度条,尽显小米"为发烧 ...
- 【css】如何实现环形进度条
最近团队的童鞋接到了一个有关环形进度条的需求,想要还原一个native的沿环轨迹渐变进度条的效果,看到这个效果的时候,笔者陷入了沉思.. 环形进度条的效果,最先想到的就是使用CSS利用两个半圆的hac ...
- 自定义环形进度条RoundProgressBar
一.效果图: Canvas画圆环说明: 圆环宽度不必在意,只是画笔宽度设置后达到的效果. 二.实现步骤 1.自定义View-RoundProgressBar 2.设置属性resources(decle ...
随机推荐
- Python3基础 list 推导式 生成100以内的偶数列表
Python : 3.7.0 OS : Ubuntu 18.04.1 LTS IDE : PyCharm 2018.2.4 Conda ...
- Python3基础 list remove 删除元素
Python : 3.7.0 OS : Ubuntu 18.04.1 LTS IDE : PyCharm 2018.2.4 Conda ...
- Android灯光系统--通知灯深入分析
Android灯光系统--通知灯深入分析 通知的类别 声音 振动 闪灯 APP如何发出通知灯请求 getSystemService(获得通知服务) 构造notification 类别 其他参数(颜色, ...
- linux 下 安装nginx
http://www.cnblogs.com/lovexinyi8/p/5845017.html 测试可用. 参看 https://www.cnblogs.com/liujuncm5/p/671378 ...
- Jmeter 中Cookie管理器的使用
Jmeter中有好几个地方可以管理Cookie,比如 Http Cookie Manager HTTP Header Manager jmeter.property文件中: #CookieManage ...
- django路由转发
一.路由转发 通常,我们会在每个app里,各自创建一个urls.py路由模块,然后从根路由出发,将app所属的url请求,全部转发到相应的urls.py模块中. 例如,下面是Django网站本身的UR ...
- angular组件层次与军事指挥层级职责的联系
又继续读angular文档,发现自己之前理解还是有误.按官方文档的思路service不是属于component的,是属于module的.module才是负责完整领域逻辑的单位.demo的英雄编辑器给我 ...
- URAL 2072 Kirill the Gardener 3
URAL 2072 思路: dp+离散化 由于湿度的范围很大,所以将湿度离散化 可以证明,先到一种湿度的最左端或者最右端,然后结束于最右端或最左端最优,因为如果结束于中间,肯定有重复走的路 状态:dp ...
- 雷林鹏分享:Ruby 注释
Ruby 注释 注释是在运行时会被忽略的 Ruby 代码内的注释行.单行注释以 # 字符开始,直到该行结束,如下所示: #!/usr/bin/ruby -w # 这是一个单行注释. puts &quo ...
- [Java学习] Java类的基本运行顺序
我们以下面的类来说明一个基本的 Java 类的运行顺序: 1. public class Demo{ 2. private String name; 3. private int age; 4. 5. ...