-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpaint1.html
50 lines (42 loc) · 1.1 KB
/
paint1.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
48
49
50
<!DOCTYPE html>
<head>
<meta charset=utf-8>
<title>HTML5</title>
<script src="jquery-1.5.1.js"></script>
<style type="text/css">
#xu{border: 1px solid #ccc;}
</style>
</head>
<body>
<canvas id="xu" width="500" height="400" ></canvas>
<script type="text/javascript">
var canvas = document.getElementById("xu");
var xx = canvas.getContext("2d");
xx.lineWidth = 5;
xx.strokeStyle = "blue";
var flag = false;
//当鼠标按下时
$("#xu").mousedown(function (e) {
alert("aa");
var mouseX = e.pageX - this.offsetLeft;//获得当前页面的x坐标
var mouseY = e.pageY - this.offsetTop;//y
flag = true;
xx.moveTo(mouseX,mouseY);//起始位置
});
//当鼠标抬起时
$("#xu").mouseup(function (e) {
flag = false;
});
//当鼠标移动时
$("#xu").mousemove(function (e) {
var mouseX = e.pageX - this.offsetLeft;//获得当前页面的x坐标
var mouseY = e.pageY - this.offsetTop;//y
if(flag){
xx.lineTo(mouseX,mouseY);//终止位置
xx.stroke();//结束图形
}
});
}
</script>
</body>
</html>