-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAmberPrice_ProgrammingExercise6_13.3.html
More file actions
56 lines (51 loc) · 1.84 KB
/
Copy pathAmberPrice_ProgrammingExercise6_13.3.html
File metadata and controls
56 lines (51 loc) · 1.84 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
<!DOCTYPE html>
<html>
<head>
<style>
#canvas { width: 400px;
border: 1px solid #999999;
border-collapse: collapse }
td { width: 4px; height: 4px; margin: 0px; padding: 0px; }
.blue { background-color: blue; }
.red { background-color: red; }
.white { background-color: white; }
</style>
<script type="text/javascript">
function createCanvas() {
var side = 100;
var tbody = document.getElementById("tablebody");
for (var i = 0; i < side; ++i) {
var row = document.createElement("tr");
for (var j = 0; j < side; ++j) {
var cell = document.createElement("td");
row.appendChild(cell);
}
tbody.appendChild(row);
}
document.getElementById("canvas").addEventListener(
"mousemove", processMouseMove, false);
}
function processMouseMove(e) {
if (e.target.tagName.toLowerCase() == "td") {
if (e.ctrlKey) {
e.target.setAttribute("class", "blue");
}
if (e.shiftKey) {
e.target.setAttribute("class", "red");
}
if (e.altKey) {
e.target.setAttribute("class", "white");
}
}
}
window.addEventListener("load", createCanvas, false);
</script>
</head>
<body>
<table id = "canvas">
<caption>Hold <em>Ctrl</em> (or <em>Control</em>) to draw blue.
Hold <em>Shift</em> to draw red. Hold <em>Alt</em> to erase.</caption>
<tbody id = "tablebody"></tbody>
</table>
</body>
</html>