-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcca.html
37 lines (36 loc) · 1.5 KB
/
cca.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
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>canvas鼠标画图</title>
<style>
body { background-color:#ffffff;}
#c1 { background-color: white; }
</style>
<script>
window.onload = function() {
var oC = document.getElementById('c1');
var oCG = oC.getContext('2d');
oC.onmousedown = function(ev) {
var ev = ev || window.event;
oCG.moveTo(ev.clientX-oC.offsetLeft,ev.clientY-oC.offsetTop); //ev.clientX-oC.offsetLeft,ev.clientY-oC.offsetTop鼠标在当前画布上X,Y坐标
document.onmousemove = function(ev) {
var ev = ev || window.event;//获取event对象
oCG.lineTo(ev.clientX-oC.offsetLeft,ev.clientY-oC.offsetTop);
oCG.strokeStyle='yellow';
oCG.stroke();
};
oC.onmouseup = function() {
document.onmousemove = null;
document.onmouseup = null;
};
};
};
</script>
</head>
<body >
<canvas id="c1" width='2080px' height="1900px"> <!--宽高写在html里,写在css里有问题-->
<span>该浏览器不支持canvas内容</span> <!--对于不支持canvas的浏览器显示-->
</canvas>
</body>
</html>