-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.html
More file actions
62 lines (53 loc) · 1.36 KB
/
Copy pathindex.html
File metadata and controls
62 lines (53 loc) · 1.36 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
<!DOCTYPE html>
<html lang="zh-CN">
<head>
<meta charset="UTF-8" />
<link rel="icon" href="favicon.ico" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>随机猫</title>
<style>
* {
margin: 0;
padding: 0;
}
html,
body {
height: 100%;
}
body {
display: flex;
align-items: center;
justify-content: center;
}
.image {
cursor: pointer;
max-width: 100%;
max-height: 100%;
}
.image.hidden,
.loading.hidden {
display: none;
}
</style>
</head>
<body>
<img id="cat" class="image hidden" alt="随机猫" />
<div id="loading" class="loading">loading...</div>
<script>
const CAT_URL = 'https://thecatapi.com/api/images/get?format=src&type=gif'
const img = document.getElementById('cat')
const loading = document.getElementById('loading')
function setLoading(isLoading) {
loading.classList.toggle('hidden', !isLoading)
img.classList.toggle('hidden', isLoading)
}
function loadCat() {
setLoading(true)
img.src = CAT_URL + '&time=' + Date.now()
}
img.addEventListener('load', () => setLoading(false))
img.addEventListener('click', loadCat)
loadCat()
</script>
</body>
</html>