我画你猜(一)
----- 最近同事老拉着玩一个游戏《我画你猜》,非常好玩,于是作为码农尝试着自己做个。 先实现画布的简单功能;简单的把功能封装了两个类 (1)元素类,也是整个画画功能的进入点 /*****元素类*****/ function DrawElement(cavId,clearId,eraserId){ this.ele = document.getElementById(cavId); this.clearBnt = document.getElementById(clearId); this.eraserBnt = document.getElementById(eraserId); //是否是橡皮擦模式 this.isEraser = false; this.draw = new Draw(this.ele); var that = this; //获取画笔的x和y this.getXY = function(xOrY){ if(xOrY === 'x') return this.pageX - that.ele.offsetLeft; return this.pageY - that.ele.offsetTop; } } DrawElement.prototype.init = function(){ var ele = this.ele; var draw = this