-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathquestion3.html
More file actions
89 lines (79 loc) · 1.98 KB
/
Copy pathquestion3.html
File metadata and controls
89 lines (79 loc) · 1.98 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
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
<!DOCTYPE html>
<html>
<head>
<title>Data Fetching and Skeleton Loader</title>
<style>
#loader {
width: 100%;
height: 100vh;
display: flex;
align-items: center;
justify-content: center;
background-color: #f5f5f5;
}
#loader .loading-animation {
width: 100px;
height: 100px;
border-radius: 50%;
background-color: #ddd;
animation: loaderAnimation 1s infinite ease-in-out;
}
@keyframes loaderAnimation {
0% {
transform: scale(0.5);
}
50% {
transform: scale(1);
background-color: #bbb;
}
100% {
transform: scale(0.5);
}
}
#data {
display: none;
margin-bottom: 20px;
}
#data h2 {
margin-bottom: 10px;
}
#data ul {
padding-left: 20px;
}
</style>
</head>
<body>
<div id="loader">
<div class="loading-animation"></div>
</div>
<div id="data">
<h2>Data:</h2>
<ul id="list"></ul>
</div>
<script>
document.addEventListener("DOMContentLoaded", function() {
var loader = document.getElementById("loader");
var dataDiv = document.getElementById("data");
var list = document.getElementById("list");
// Fetch data from JSON Placeholder API
fetch("https://jsonplaceholder.typicode.com/posts")
.then(response => response.json())
.then(data => {
// Hide the loader
loader.style.display = "none";
// Show the data and populate the list
dataDiv.style.display = "block";
data.forEach(item => {
var li = document.createElement("li");
li.textContent = item.title;
list.appendChild(li);
});
})
.catch(error => {
console.error(error);
loader.textContent = "Error occurred while fetching data.";
});
});
</script>
</body>
</html>