亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

用ES6寫法 寫一個canvas類,頁面未生成canvas圖像

用ES6寫法 寫一個canvas類,頁面未生成canvas圖像

DIEA 2019-03-23 19:15:57
    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)
查看完整描述

2 回答

?
慕少森

TA貢獻2019條經驗 獲得超9個贊

this.ctx.canvas.width = width

this.ctx.canvas.height = height

this.width = width

this.height = height


查看完整回答
反對 回復 2019-03-29
?
臨摹微笑

TA貢獻1982條經驗 獲得超2個贊

沒有編譯吧。瀏覽器不認識class


查看完整回答
反對 回復 2019-03-29
  • 2 回答
  • 0 關注
  • 661 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號