-
Notifications
You must be signed in to change notification settings - Fork 0
/
cats.html
88 lines (79 loc) · 2.27 KB
/
cats.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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Random Kitten Generator</title>
<style>
body {
font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
text-align: center;
background-color: #f8f9fa;
margin: 0;
padding: 0;
}
header {
background-color: #007bff;
color: #fff;
padding: 20px 0;
margin-bottom: 20px;
}
h1 {
font-size: 2.5rem;
margin: 0;
}
#kitten-container {
display: flex;
justify-content: center;
align-items: center;
height: 70vh;
position: relative;
}
#kitten-image {
max-width: 90%;
max-height: 90%;
border-radius: 10px;
box-shadow: 0 0 20px rgba(0, 0, 0, 0.2);
}
button {
padding: 10px 20px;
font-size: 1rem;
background-color: #ffc107;
color: #212529;
border: none;
border-radius: 5px;
cursor: pointer;
transition: background-color 0.3s ease;
position: absolute;
bottom: 20px;
left: 50%;
transform: translateX(-50%);
}
button:hover {
background-color: #ffca28;
}
</style>
</head>
<body>
<header>
<h1>Random Kitten Generator</h1>
</header>
<div id="kitten-container">
<img id="kitten-image" src="" alt="Random Kitten">
<button onclick="getRandomKitten()">Show Another Kitten</button>
</div>
<script>
function getRandomKitten() {
fetch('https://api.thecatapi.com/v1/images/search')
.then(response => response.json())
.then(data => {
const kittenImage = document.getElementById('kitten-image');
kittenImage.src = data[0].url;
})
.catch(error => console.error('Error fetching kitten:', error));
}
// Load a random kitten image when the page loads
window.onload = getRandomKitten;
</script>
</body>
</html>