After delving into some research regarding Bootstrap-compatible spinners, I stumbled upon a piece of code. Take a look:
function getData() {
var spinner = document.getElementById("spinner");
spinner.style.display = "block";
setTimeout(function () {
fetch("https://jsonplaceholder.typicode.com/posts")
.then((response) => response.json())
.then((data) => {
data.forEach((item) => {
var div = document.createElement("div");
var p = document.createElement("p");
p.innerText = item.title;
div.appendChild(p);
document.getElementById("dataContainer").appendChild(div);
});
spinner.style.display = "none";
});
}, 5000);
}
getData();
<!-- begin snippet: js hide: false console: true babel: false -->
#spinner {
position: absolute;
top: 49%;
left: 47%;
width: 3.5rem;
height: 3.5rem;
/* transform: translate(-50%, -50%); */
display: none;
}
<!DOCTYPE html>
<html>
<head>
<title>Bootstrap Spinner Tutorial</title>
<link href="https://cdn.jsdelivr.net/npm/<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="8defe2e2f9fef9ffecfdcdb8a3bda3bf">[email protected]</a>/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-EVSTQN3/azprG1Anm3QDgpJLIm9Nao0Yz1ztcQTwFspd3yD65VohhpuuCOmLASjC" crossorigin="anonymous" />
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" />
</head>
<body>
<div class="spinner-border m-5" role="status" id="spinner">
<span class="visually-hidden">Loading...</span>
</div>
<div id="dataContainer"></div>
<script src="https://cdn.jsdelivr.net/npm/<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="6e0c01011a1d1a1c0f1e2e5b405e405c">[email protected]</a>/dist/js/bootstrap.bundle.min.js" integrity="sha384-MrcW6ZMFYlzcLA8Nl+NtUVF0sA7MsXsP1UyJoMp4YLEuNSfAP+JcXn/tWtIaxVXM" crossorigin="anonymous"></script>
</body>
</html>
I aim to have it smoothly fade in and out for visual appeal. While I did come across some related queries here on StackOverflow, they didn't offer much assistance. Let me know if you have any suggestions or solutions.