-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmouseposition.html
More file actions
67 lines (57 loc) · 2.22 KB
/
mouseposition.html
File metadata and controls
67 lines (57 loc) · 2.22 KB
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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
<!--
To change this template use Tools | Templates.
-->
<!DOCTYPE html>
<html>
<head>
<title>Mouse Position</title>
<meta charset="utf-8" />
<meta name="viewport" content="width=1024" />
<meta name="apple-mobile-web-app-capable" content="yes" />
<style type="text/css">
canvas.default { border: 1px solid black; }
textarea { border: 1px solid #888; width: 300px; height: 100px; }
</style>
<script>
window.onload = function () {
var canvas = document.getElementById('canvas');
// Get a reference to the drawing context
var ctx = canvas.getContext('2d');
// Set the fill pattern
ctx.fillStyle = 'gray';
// Set the font
ctx.font = "italic 200 36px/2 Unknown Font, sans-serif";
ctx.fillText("Perform", 20, 40);
ctx.fillText("mouse events", 20, 80);
ctx.fillText("inside the canvas", 20, 120);
function onMouseEvent (event) {
var text = document.getElementById('feedback');
text.value = 'x: ' + event.pageX + ' y: ' + event.pageY;
}
function onMouseEvent1 (event) {
var text = document.getElementById('feedback1');
var x, y;
var offsetLeft = canvas.offsetLeft;
var offsetTop = canvas.offsetTop;
x = event.pageX;
y = event.pageY;
x -= offsetLeft;
y -= offsetTop;
text.value = 'x: ' + x + ' y: ' + y;
}
document.addEventListener('mousemove', onMouseEvent, false);
canvas.addEventListener('mousemove', onMouseEvent1, false);
};
</script>
</head>
<body>
<p>
<a href="index.html">Back to index</a>
</p>
<canvas id="canvas" width="300" height="200" tabindex='0' class="default">
This browser or document mode doesn't support canvas
</canvas>
<textarea id="feedback"></textarea>
<textarea id="feedback1"></textarea>
</body>
</html>