-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathcanvas_script.js
48 lines (39 loc) · 1.25 KB
/
canvas_script.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
function onBodyLoad(){
$("div#postit").css("margin-left",function () {
return (($(window).width() / 2) - 300)+"px";
});
}
function onCanvas(){
var myCanvas = document.getElementById('canvas');
var context = myCanvas.getContext("2d");
$("#canvas").mousedown(function(evt){
var offset = $("#canvas").offset();
context.beginPath();
context.moveTo(evt.pageX - offset.left - 25, evt.pageY - offset.top + 5 );
$(document).mousemove(function(evt){
var offset = $("#canvas").offset();
context.lineTo(evt.pageX - offset.left - 25, evt.pageY - offset.top + 5);
context.lineWidth = 1;
context.strokeStyle ='orange';
context.stroke();
}).mouseup(function(){
$( document ).unbind('mousemove');
$( document ).unbind('mouseup');
});
});
}
function moveCanvas(){
$( document ).mousemove(function(evt){
//document.style.cursor='move';
$( '#postit' ).offset({ top: evt.pageY, left: evt.pageX})
}).mousedown(function(evt){
$( document ).unbind('mousemove');
$( document ).unbind('mousedown');
//document.style.cursor='default';
});
}
function clearCanvas(){
var myCanvas = document.getElementById('canvas');
var context = myCanvas.getContext("2d");
context.clearRect(0,0,myCanvas.width,myCanvas.height);
}