账号密码登录
微信安全登录
微信扫描二维码登录

登录后绑定QQ、微信即可实现信息互通

手机验证码登录
找回密码返回
邮箱找回 手机找回
注册账号返回
其他登录方式
分享
  • 收藏
    X
    用ES6写法 写一个canvas类,页面未生成canvas图像
    20
    0
        let canvasNode = document.getElementById('canvas'),
            ctxs = canvasNode.getContext("2d");
    
        console.log(canvasNode)
    
    
        class CircleProgress {
            constructor(ctxs, width, height, arc) {
                this.ctx = ctxs
                this.ctx.canvas.width = width
                this.ctx.canvas.height = width
                this.arc = arc
            }
    
            clearFill() {
                this.ctx.clearRect(0, 0, this.width, this.width);
            }
    
            fillBg() {
                this.ctx.beginPath();
                this.ctx.lineWidth = this.arc;
                this.ctx.strokeStyle = '#ccc';
                this.ctx.arc(this.width / 2, this.width / 2, 45, 0, 2 * Math.PI);
                this.ctx.stroke();
            }
    
            fillArc(x) {
                this.ctx.beginPath();
                this.ctx.lineWidth = this.arc;
                this.ctx.strokeStyle = '#ccc';
                this.ctx.arc(this.width / 2, this.width / 2, 45, -90 * Math.PI / 180, (x * 3.6 - 90) * Math.PI / 180);
                this.ctx.stroke();
            }
    
            fillText(x) {
                this.ctx.font = '14px' + ' Arial';
                this.ctx.fillStyle = 'red';
                this.ctx.textBaseline = "middle";
                this.ctx.textAlign = 'center';
                this.ctx.fillText(x.toFixed(1) + '%', this.width / 2, this.width / 2);
            }
    
            fill(x) {
                this.fillBg();
                this.fillArc(x);
                this.fillText(x);
            }
    
            testFn() {
                return this.ctx
            }
    
        }
    
        let cicle = new CircleProgress(ctxs, 100, 100, 10)
    
        cicle.fill(100)
    0
    打赏
    收藏
    点击回答
        全部回答
    • 共 0 条
    更多回答
    扫一扫访问手机版
    • 回到顶部
    • 回到顶部