I'm trying to draw a rectangle with mouse events, it seems to work, I've used console.log in all my code to see what is happening, and is all running nice, but the rectangle just dislikes me I think, it doesn't appear!
I can't figure out how to find the mistake!
I only want a direction, thank you for your time.
And the code here:
$("body").wrapInner("<canvas id='myCanvas'>");
var canvas = $("#myCanvas").css("cursor", "crosshair");
var context = canvas[0].getContext("2d");
var div = {x:0, y:0};
var draw_rectangle = function(e){
context.fillRect (
div.x, div.y,
(e.pageX - div.x),
(e.pageY - div.y)
);
};
context.fillStyle = "#aaf";
canvas.on("mousedown", function(e){
div.x = e.pageX;
div.y = e.pageY;
canvas.on("mousemove", draw_rectangle);
});
canvas.on("mouseup", function(){
canvas.off("mousemove");
console.log("Drawed.");
});