-
Notifications
You must be signed in to change notification settings - Fork 165
/
index.html
47 lines (45 loc) · 1.95 KB
/
index.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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8" />
<title>HTML5 Games</title>
<link rel="stylesheet" href="style.css" />
</head>
<body>
<header>
<h1 id="title">Bounce</h1>
<p id="expand">Expand for more games.</p>
<p id="select">Select a game.</p>
<ul id="nav">
<li><a href="#bounce" data-game="bounce" class="selected">Bounce</a></li>
<li><a href="#snake" data-game="snake">Snake</a></li>
<li><a href="#tetris" data-game="tetris">Tetris</a></li>
<li><a href="#defender" data-game="defender">Defender</a></li>
<li><a href="#pacman" data-game="pacman">Pacman</a></li>
<li><a href="#puzzle" data-game="puzzle">Puzzle</a></li>
<li><a href="#spider" data-game="spider">Spider</a></li>
</ul>
</header>
<iframe id="machine"></iframe>
<script>
function play(game) {
"use strict";
document.querySelector("#nav li a.selected").className = "";
document.querySelector(`#nav li a[data-game=${game}]`).className = "selected";
document.getElementById("title").innerHTML = game;
document.getElementById("machine").src = `${game}/index.html`;
document.title = "HTML5 Games: " + game.substring(0, 1).toUpperCase() + game.substring(1);
}
window.addEventListener("load", () => {
"use strict";
const header = document.querySelector("header");
play(location.hash.substring(1) || "bounce");
document.querySelector("#nav").addEventListener("click", (e) => {
if (e.target.dataset.game) {
play(e.target.dataset.game);
}
});
}, false);
</script>
</body>
</html>