blob: 6cfa56ade3a339d9632b9d2d4334d08239a0e799 (
plain)
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
68
69
70
|
<!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>
<title>An element that disappears on click</title>
<style>
#under {
position: absolute;
top: 20px;
left: 20px;
width: 100px;
height: 100px;
background-color: white;
}
#partially_under {
position: absolute;
top: 20px;
left: 10px;
width: 100px;
height: 100px;
background-color: blue;
opacity: 0.5;
}
#over {
position: absolute;
top: 20px;
left: 20px;
width: 100px;
height: 100px;
background-color: red;
opacity: 0.5;
}
#log {
position: absolute;
top: 120px;
}
</style>
</head>
<body id="body">
<div id="under"><p id="contents">Hello</p></div>
<div id="partially_under"><p id="other_contents">Hello</p></div>
<div id="over"></div>
<div id="log">
<p>Log:<p>
</div>
<script>
var byId = document.getElementById.bind(document);
var log = byId("log");
function handler(ev) {
log.innerHTML += "<p></p>";
log.lastElementChild.textContent = ev.type + " in " + ev.target.id + " (handled by " + ev.currentTarget.id + ")\n";
}
var under = byId("under");
var over = byId("over");
var body = document.body;
var types = ["click", "mousedown", "mouseup"];
for (var i = 0, type; (type = types[i]); ++i) {
under.addEventListener(type, handler);
over.addEventListener(type, handler);
body.addEventListener(type, handler);
}
</script>
</body>
</html>
|