<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>

HTML5 Canvas菜鸟教程

HTML5 Canvas绘制环形进度条

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

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

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

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

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

  3. canvas绘制环形进度条

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

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

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

  5. canvas实现半圆环形进度条

    html部分 <canvas id="canvas" width="150" height="150"> <p>抱歉 ...

  6. Canvas实现环形进度条

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

  7. 仿MIUI音量变化环形进度条实现

    Android中使用环形进度条的业务场景事实上蛮多的,比方下载文件的时候使用环形进度条.会给用户眼前一亮的感觉:再比方我大爱的MIUI系统,它的音量进度条就是使用环形进度条,尽显小米"为发烧 ...

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

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

  9. 自定义环形进度条RoundProgressBar

    一.效果图: Canvas画圆环说明: 圆环宽度不必在意,只是画笔宽度设置后达到的效果. 二.实现步骤 1.自定义View-RoundProgressBar 2.设置属性resources(decle ...

随机推荐

  1. MVC 学习

    基础概念学习:http://www.cnblogs.com/meetyy/p/3451933.html 路由:http://www.cnblogs.com/meetyy/p/3453189.html ...

  2. linux中线程池【转】

    本文转载自:http://blog.csdn.net/yusiguyuan/article/details/18401277 一.线程池 大多数的网络服务器,包括Web服务器都具有一个特点,就是单位时 ...

  3. linux之cut用法--转载

    cut是一个选取命令,就是将一段数据经过分析,取出我们想要的.一般来说,选取信息通常是针对“行”来进行分析的,并不是整篇信息分析的. (1)其语法格式为:cut  [-bn] [file] 或 cut ...

  4. plsql过期解决方法

    1.首先,登陆PL/SQL Developer,PL/SQL Developer要到期了 2.输入指令“regedit”打开注册表,如图所示 3.然后,在注册表里按HKEY_CURRENT_USER\ ...

  5. Hibernate 由实体类与配置文件的配置关系生成数据库中的表

    import org.hibernate.cfg.Configuration; import org.hibernate.tool.hbm2ddl.SchemaExport; public class ...

  6. poj 2480 Longge's problem 欧拉函数+素数打表

    Longge's problem   Description Longge is good at mathematics and he likes to think about hard mathem ...

  7. HDU 6015 Skip the Class

    Skip the Class 代码: #include<bits/stdc++.h> using namespace std; #define ll long long #define l ...

  8. 为arm 编译包含gd的php5

    1) 下载gd的各种依赖包. 但是不要下载gd本身,因为这是包含在php里的. 探索的时候也下载了 libvpx freetype,可惜最后的编译没过,就没有用上 2)编译各种(编译前记得把各种环境变 ...

  9. 雷林鹏分享:C# 异常处理

    C# 异常处理 异常是在程序执行期间出现的问题.C# 中的异常是对程序运行时出现的特殊情况的一种响应,比如尝试除以零. 异常提供了一种把程序控制权从某个部分转移到另一个部分的方式.C# 异常处理时建立 ...

  10. Style样式的四种使用(包括用C#代码动态加载资源文件并设置样式)

    Posted on 2012-03-23 11:21 祥叔 阅读(2886) 评论(6) 编辑 收藏 在Web开发中,我们通过CSS来控制页面元素的样式,一般常用三种方式: 1.       内联样式 ...