设为首页 - 加入收藏 ASP站长网(Aspzz.Cn)- 科技、建站、经验、云计算、5G、大数据,站长网!
热搜: 创业者 数据 手机
当前位置: 首页 > 站长学院 > MySql教程 > 正文

探究 canvas 绘图中撤销(undo)功能的实现方式详解(3)

发布时间:2020-05-12 03:44 所属栏目:115 来源:站长网
导读:class WrappedCanvas {constructor (canvas) {this.ctx = canvas.getContext('2d');this.width = this.ctx.canvas.width;this.height = this.ctx.canvas.height;this.executionArray = [];}drawImage (...params) {

class WrappedCanvas { constructor (canvas) { this.ctx = canvas.getContext('2d'); this.width = this.ctx.canvas.width; this.height = this.ctx.canvas.height; this.executionArray = []; } drawImage (...params) { this.executionArray.push({ method: 'drawImage', params: params }); this.ctx.drawImage(...params); } clearCanvas () { this.ctx.clearRect(0, 0, this.width, this.height); } undo () { if (this.executionArray.length > 0) { // 清空画布 this.clearCanvas(); // 删除当前操作 this.executionArray.pop(); // 逐个执行绘图动作进行重绘 for (let exe of this.executionArray) { this[exe.method](...exe.params) } } } }

(编辑:ASP站长网)

网友评论
推荐文章
    热点阅读