-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMiniPaint.html
47 lines (44 loc) · 1.22 KB
/
MiniPaint.html
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
<!DOCTYPE HTML>
<html>
<head>
<style>
body {
margin: 0px;
padding: 0px;
}
</style>
</head>
<body>
<div id="status"></div>
<canvas id="myCanvas" width="600px" height="600px"></canvas>
<script type="text/javascript" src="http://code.jquery.com/jquery-latest.js"></script>
<script type="text/javascript">
jQuery(document).ready(function(e){
var clicked = false;
$(document).mousemove(function(e){
$('#status').html(e.pageX +', '+ e.pageY);
var canvas = document.getElementById('myCanvas');
var context = canvas.getContext('2d');
console.log(canvas);
canvas.addEventListener('mousedown', function(event){
console.log("Mousedown!");
clicked = true;
context.beginPath();
context.moveTo(event.pageX, event.pageY);
}, false);
canvas.addEventListener('mousemove', function(event){
context.lineTo(event.pageX, event.pageY);
if (clicked === true){
context.stroke();
}
}, false);
document.addEventListener('mouseup', function(event){ //prevents a click off-canvas from drawing
clicked = false;
console.log("you're at mouseup");
console.log("what now?");
}, false);
});
});
</script>
</body>
</html>