-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.html
75 lines (66 loc) · 1.75 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
<!DOCTYPE html>
<html>
<head>
<title>Dog Gallery</title>
<style>
/* CSS styles */
body {
font-family: Arial, sans-serif;
background-color: #f5f5f5;
margin: 0;
padding: 20px;
}
h1 {
text-align: center;
color: #333;
}
.gallery {
display: flex;
flex-wrap: wrap;
justify-content: center;
margin-top: 20px;
}
.gallery-item {
width: 300px;
margin: 10px;
box-shadow: 0 0 5px rgba(0, 0, 0, 0.3);
}
.gallery-item img {
width: 100%;
height: auto;
}
</style>
<script>
// JavaScript code
document.addEventListener("DOMContentLoaded", function() {
var gallery = document.getElementById("gallery");
// Make AJAX request to fetch multiple random dog images
var xhr = new XMLHttpRequest();
xhr.open("GET", "https://dog.ceo/api/breeds/image/random/3");
xhr.onreadystatechange = function() {
if (xhr.readyState === XMLHttpRequest.DONE && xhr.status === 200) {
var response = JSON.parse(xhr.responseText);
var images = response.message;
// Loop through the images and create gallery items
for (var i = 0; i < images.length; i++) {
var galleryItem = document.createElement("div");
galleryItem.className = "gallery-item";
var img = document.createElement("img");
img.src = images[i];
img.alt = "Dog " + (i + 1);
galleryItem.appendChild(img);
gallery.appendChild(galleryItem);
}
}
};
xhr.send();
});
</script>
</head>
<body>
<h1>Dog Gallery</h1>
<div class="gallery" id="gallery">
<!-- Images will be dynamically added here -->
</div>
</body>
</html>