forked from mrduncan/marker
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathapp.js
56 lines (45 loc) · 1.2 KB
/
app.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
$(function () {
function getMousePosition(event) {
return { x: event.pageX, y: event.pageY };
}
var isDrawing = false,
canvas = $("#canvas"),
context;
canvas.attr("height", $(window).height() - 64);
canvas.attr("width", $(window).width());
context = canvas.get(0).getContext("2d");
context.lineWidth = 10.0;
context.miterLimit = 5.0;
context.strokeStyle = "red";
canvas.bind("mousedown", function (e) {
var point = getMousePosition(e);
context.beginPath();
context.moveTo(point.x, point.y);
isDrawing = true;
e.preventDefault();
});
canvas.bind("mousemove", function (e) {
var point;
if (isDrawing) {
point = getMousePosition(e);
context.lineTo(point.x, point.y);
context.stroke();
}
});
canvas.bind("mouseup", function (e) {
isDrawing = false;
});
canvas.bind("mouseout", function (e) {
isDrawing = false;
});
$("#black, #red").click(function (e) {
context.lineWidth = 10.0;
context.strokeStyle = $(this).css("background-color");
e.preventDefault();
});
$("#eraser").click(function (e) {
context.lineWidth = 25.0;
context.strokeStyle = "#fff";
e.preventDefault();
});
});