-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
124 lines (118 loc) · 4.23 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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>HTML~~</title>
<style>
* {
margin: 0;
text-decoration: none;
}
.ribbon {
position: fixed;
right: 0px;
top: 0px;
z-index: 1001;
}
#backto-index {
position: fixed;
bottom: 0;
left: 0;
z-index: 1001;
}
#router-view {
position: fixed;
z-index: 1000;
width: 100vw;
height: 100vh;
}
#the-index {
font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Helvetica, Arial, sans-serif, "Apple Color Emoji", "Segoe UI Emoji", "Segoe UI Symbol";
overflow-y: scroll;
width: 100vw;
height: 100vh;
}
#the-index > * {
margin: 20px;
}
#the-index a {
text-decoration: none;
color: #0366d6;
}
#the-index a:hover {
text-decoration: underline;
}
#the-index li {
margin: 10px 0;
}
#backto-index {
margin: 10px;
}
#backto-index a {
font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Helvetica, Arial, sans-serif, "Apple Color Emoji", "Segoe UI Emoji", "Segoe UI Symbol";
text-decoration: none;
color: #0366d6;
}
#backto-index a:hover {
text-decoration: underline;
}
</style>
</head>
<body>
<div id="widget" class="ribbon">
<a href="https://github.com/huamurui/html-s"><img decoding="async" loading="lazy" width="149" height="149" src="https://github.blog/wp-content/uploads/2008/12/forkme_right_darkblue_121621.png?resize=149%2C149" class="attachment-full size-full" alt="Fork me on GitHub" data-recalc-dims="1" /></a>
</div>
<div id="backto-index"><a href="./#">home</a></div>
<div id="router-view"></div>
<script>
// I want to make a simple fe-router here
window.addEventListener("DOMContentLoaded", onHashChange)
window.addEventListener("hashchange", onHashChange)
// window.addEventListener("popstate", onPopState) // history 需要服务器那边简单配一下,...如果不是自己部署服务,可能并不是很适用,虽然 hash 有点丑...凑活吧。而且区别也没那么大。
function onHashChange() {
renderView(location.hash)
}
let routerView = document.getElementById("router-view")
let widget = document.getElementById("widget")
function renderView(name) {
if (name === "") {
routerView.innerHTML = ""
routerView.appendChild(renderList(list))
widget.style.display = "block"
} else {
const path = name.replace("#/", "")
routerView.innerHTML = `<iframe src="${path}.html" frameborder="0" style="width: 100%; height: 100%;"></iframe>`
widget.style.display = "none"
}
}
// the file under this dir
const list = ["drag-tree", "floating-action-button", "virtual-scrolling", "virtual-waterfall", "markdown-to-markup", "damaku", "a-page", "dialogue-bubbles", "dialogue-chat-ui", "heatmap", "fluid", "slider", "slider-paper-onboarding0", "snake", "mario", 'b-page', "piano", "shadow"]
const favo = ["floating-action-button", "virtual-waterfall", "piano"]
function renderList(list) {
const theIndex = document.createElement("div")
theIndex.id = "the-index"
const h = document.createElement("h1")
const desc = document.createElement("p")
const ul = document.createElement("ul")
h.innerText = "HTML engineer~"
desc.innerText = "i want to make some simple demo just through single html file."
list.forEach((item) => {
const li = document.createElement("li")
const a = document.createElement("a")
a.href = `#/${item}`
a.innerText = item
li.appendChild(a)
if(favo.includes(item)){
li.appendChild(document.createTextNode("🥰"))
}
ul.appendChild(li)
})
theIndex.appendChild(h)
theIndex.appendChild(desc)
theIndex.appendChild(ul)
return theIndex
}
</script>
</body>
</html>