Canvas click
JavaScript
Canvas = function (element) {
this.canvas = document.createElement("canvas");
this.context = this.canvas.getContext('2d');
this.canvas.id = "display";
var style = {
"width": "100",
"height": "100"
};
for (var index in style) {
this.canvas[index] = style[index];
}
element == undefined ? document.body.appendChild(this.canvas) : element.appendChild(this.canvas);
this.canvas.addEventListener("mousemove", this.click.bind(this), false);
}
Canvas.prototype.of = function (mouse) {
console.log("x: " + mouse[0] + ", y: " + mouse[1]);
}
Canvas.prototype.click = function (e) {
this.mouse = [e.clientX, e.clientY];
return this.of(this.mouse);
}
var myCanvas = new Canvas();
myCanvas.context.fillRect(0, 0, 50, 50);
var myCanvas2 = new Canvas();
myCanvas2.context.fillRect(0, 0, 60, 60);