-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcanvas-drawline2.html
41 lines (38 loc) · 1.14 KB
/
canvas-drawline2.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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Document</title>
<style type="text/css">
body{
background-color: black;
}
canvas{
background-color: white;
}
</style>
<script type="text/javascript">
window.onload= function(){
var oc= document.getElementById('c1');
var ogc=oc.getContext('2d');
oc.onmousedown = function(ev){
var ev=ev || window.event;
ogc.moveTo(ev.clientX-oc.offsetLeft,ev.clientY-oc.offsetTop);
document.onmousemove = function(ev){
var ev = ev || window.event;
ogc.lineTo(ev.clientX-oc.offsetLeft,ev.clientY-oc.offsetTop);
ogc.stroke();
};
document.onmouseup = function(){
document.onmousemove = null;
document.onmouseup = null;
};
}
}
</script>
</head>
<body>
<canvas id="c1" width="400" height="400">
</canvas>
</body>
</html>