import React from 'react';
import Tools from '../../tools/index'
export default class PercentageRing extends React.Component {
constructor(props){
super(props);
}
componentDidMount() {
let canvas = this.refs.ring;
let width = canvas.offsetWidth;
let height = canvas.offsetHeight;
let context = canvas.getContext('2d');
// this.rings();
let i = 1;
let percent = 30;
this.timerId = setInterval(()=>{
i >= percent && clearInterval(this.timerId);
context.clearRect(0,0,width+10,height);
this.draw(i++);
},50)
}
draw(i){
let canvas = this.refs.ring;
let width = canvas.offsetWidth;
let height = canvas.offsetHeight;
let context = canvas.getContext('2d');
let rad = Math.PI*2/100;
canvas.width = width;
canvas.height = height;
// 绘制一个圆
context.beginPath(); // 开始创建路径
context.arc(width/2,height/2,height/2-10,0,2*Math.PI,false);
context.lineWidth = 10;
context.strokeStyle="#12365a"; // 轮廓颜色
context.lineCap = "round"; // 绘制圆帽
context.stroke(); // 通过线条来绘制轮廓
context.closePath(); // 关闭路径
// this.draw();
context.beginPath();
context.font = `${72/320}rem PingFang SC`;
context.textAlign = 'right';
context.textBaseline = 'bottom';
context.fillStyle="#00a8ff";
context.fillText('%',width/2+110,height/2+25);
context.stroke();
context.closePath();
// 绘制半圆
context.beginPath();
context.arc(width/2,height/2,height/2-10,-Math.PI/2,-Math.PI/2+i*rad,false);
context.lineWidth = 10;
// 创建渐变颜色
let linearGrad = context.createLinearGradient(0,0,width,height);
linearGrad.addColorStop(0.0, '#02a7ff');
linearGrad.addColorStop(0.25, '#1da1fb');
linearGrad.addColorStop(0.5, '#5893f4');
linearGrad.addColorStop(0.75, '#9484ec');
context.strokeStyle = linearGrad;
context.stroke();
context.closePath();
// 绘制文本信息
context.beginPath();
context.font = `${236/302}rem PingFang SC`;
context.textAlign = 'center';
context.textBaseline = 'middle';
context.fillStyle = "#00a8ff";
context.fillText(i.toFixed(0),width/2,height/2); // 绘制文本最大宽度
context.stroke();
context.closePath();
}
componentWillUnmount(){
  this.timerId && clearInterval(this.timerId);
}
render() {
return (
<div className="perent-ring-box">
<canvas className="perent-canvas" ref='ring'>
<p>请使用最新的谷歌、火狐、IE浏览器</p>
<p>您的浏览器不支持</p>
</canvas>
</div>
)
 
}
}

react canvas圆环动态百分比的更多相关文章

  1. [canvas]通过动态生成像素点做绚丽效果

    本例中的粒子就是实实在在的像素,由js代码在canvas上动态生成的像素点!这些像素点通过一个运动方法有规律地动了起来.透过这个思路,我们可以想到很多很炫的效果,但是这个性能有待考察.实验证明,动态控 ...

  2. Canvas制作动态进度加载水球

    <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...

  3. React Canvas:高性能渲染 React 组

    React Canvas 提供了使用 Canvas 渲染移动 Web App 界面的能力,替代传统的 DOM 渲染,具有更接近 Native App 的使用体验.React Canvas 提供了一组标 ...

  4. 结合ItemsControl在Canvas中动态添加控件的最MVVM的方式

    今天很开心的收获: ItemsControl 中 ItemsPanel的重定义和 ItemContainerStyle 以及 ItemTemplate 三者的巧妙结合,在后台代码不实例化任何控件的前提 ...

  5. Canvas之动态波浪效果_陈在真Sunny_chen_新浪博客

    Canvas之动态波浪效果_陈在真Sunny_chen_新浪博客 Canvas之动态波浪效果 (2012-04-26 09:04:51) 转载▼

  6. JS canvas标签动态绘制图型

    使用canvas标签动态绘制图型,当点击鼠标时,以鼠标点击的坐标作为图形中心点.当点击数为偶数时画三角形,当点击数为奇数时画五角星 <!DOCTYPE HTML> <html> ...

  7. react将表格动态生成视频列表【代码】【案例】

    只需要创建一个表格,id为videos,react就能将这个表格转换成视频列表,并点击自动播放 index.html <!DOCTYPE html> <html> <he ...

  8. JS框架_(JQbar.js)柱状图动态百分比进度条特效

    百度云盘 传送门 密码:q6rt 柱状图动态百分比进度条效果 <html> <head> <title>jqbar.js柱状图动态百分比进度条特效</titl ...

  9. React用dangerouslySetInnerHTML动态渲染HTML

    React用dangerouslySetInnerHTML动态渲染HTML React项目,需要把后台返回的一段html代码在页面上显示 在render获取内容, //在render里获取内容 con ...

随机推荐

  1. MySQL ERROR 1698 (28000): Access denied for user 'root'@'localhost'

    今天在安装MySQL的过程中竟然没有让我输入密码,登录的时候也不需要密码就能进入,这让我很困惑. 进了数据库就设置密码,用了各种方式都不行. 虽然我这数据库没啥东西但也不能没有密码就裸奔啊,有点丢人是 ...

  2. BottomNavigationBarItem fixed

    BottomNavigationBar( type: BottomNavigationBarType.fixed, onTap: (value){ if more then 3 items,, use ...

  3. Dell3470无法开机或开机黑屏情况下检测屏幕是否正常

    故障现象:Dell3470无法开机,点击开关按键无任何反应 故障分析:释放静电后故障依旧.更换电源适配器后故障依旧,初判主板故障,无法确认屏是否正常 解决方法:除去拆机单独测试外,Dell售后告知一个 ...

  4. kubernets controller 和 CRD的扩展

    sample git repo 各个组件开发指导 operator 介绍 此图来自谷歌员工的实践介绍 client-go的使用和源码分析 (dlv) p pods *k8s.io/api/core/v ...

  5. Vue-admin工作整理(十二):Vuex-插件(持久化存储)

    Vuex可以支持插件形式,来处理指定业务,比如:持久化存储的插件(当每次刷新浏览器的时候store里面的参数都会被清除,因为它是存在内存中的,而不是存在本地的,有时候我们希望将一些东西存在本地) 插件 ...

  6. Map.putAll方法

    import Java.util.HashMap; public class Map_putAllTest { public static void main(String[] args){    / ...

  7. Idea 里明明配置了Tomcat,但是右上角任然没有Tomcat显示

    问题截图如下: 上图明明配置了Tomcat,但是Idea右上角任然是Add Configurations 因为这个问题,困扰了好久.解决方法: 点击Add Configurations   出现如下界 ...

  8. English trip V2 - 5 Technology Teacher:Taylor Key:adjective + preposition

    In this lesson you will learn to talk about technology and innovation. 课上内容(Lesson) What is your fav ...

  9. Python自学:第三章 使用del语句删除元素

    motorcycles = ["honda", "yamaha", "suzuki"] print(motorcycles) del mot ...

  10. Git笔记整理

    git 分支:   &.创建分支      创建分支很简单:git branch <分支名>       &.切换分支      git checkout <分支名& ...