首页 技术 正文
技术 2022年11月20日
0 收藏 640 点赞 2,924 浏览 1768 个字

<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绘制环形进度条

相关推荐
python开发_常用的python模块及安装方法
adodb:我们领导推荐的数据库连接组件bsddb3:BerkeleyDB的连接组件Cheetah-1.0:我比较喜欢这个版本的cheeta…
日期:2022-11-24 点赞:878 阅读:9,484
Educational Codeforces Round 11 C. Hard Process 二分
C. Hard Process题目连接:http://www.codeforces.com/contest/660/problem/CDes…
日期:2022-11-24 点赞:807 阅读:5,899
下载Ubuntn 17.04 内核源代码
zengkefu@server1:/usr/src$ uname -aLinux server1 4.10.0-19-generic #21…
日期:2022-11-24 点赞:569 阅读:6,732
可用Active Desktop Calendar V7.86 注册码序列号
可用Active Desktop Calendar V7.86 注册码序列号Name: www.greendown.cn Code: &nb…
日期:2022-11-24 点赞:733 阅读:6,485
Android调用系统相机、自定义相机、处理大图片
Android调用系统相机和自定义相机实例本博文主要是介绍了android上使用相机进行拍照并显示的两种方式,并且由于涉及到要把拍到的照片显…
日期:2022-11-24 点赞:512 阅读:8,125
Struts的使用
一、Struts2的获取  Struts的官方网站为:http://struts.apache.org/  下载完Struts2的jar包,…
日期:2022-11-24 点赞:671 阅读:5,285