I want to show a spinning wheel (throbber) when clicking on the div element Menu option1. When an element is clicked in a browser, the viewer is waiting for the page to reload. The waiting time for the page to reload includes sending the information to server, resolving it and then sending the information back again and as the last step loading the page.
I tried to do it with my code below. The problem is that I only see the spinning wheel during the last page loading step, which is only a fraction of the time it takes to wait after clicking on the element. I would like to display the spinning wheel when clicking on the div element Menu option1.
How can I do this?
Since the page is loading too fast to really see the spinning wheel, this can be simulated by using DevTools (Shift+Ctrl+J in chrome) DevTools>Network>Throttling>Slow 3G
or by doing some changes in the HTML, for example, adding an extra
<div class="Menu4" style="border: solid;width:100px;">Menu option4</div>
in https://codepen.io/G1111/pen/zYMrQmq
// deletes the spinning wheel when page is loaded:
window.addEventListener("load", () => {
document.querySelector(".loader").classList.remove("loader-active");
});
.loader {
position: fixed;
top: 0;
left: 0;
width: 100%;
height: 100%;
display: none;
align-items: center;
justify-content: center;
background: gray;
background-color: rgba(0, 0, 0, .5);
}
.loader-active {
display: flex;
}
.loader::after {
content: "";
width: 180px;
height: 180px;
background-image: url("https://tradinglatam.com/wp-content/uploads/2019/04/loading-gif-png-4.gif");
}
<div class="Menu1" style="border: solid;width:100px;">Menu option1</div>
<div class="Menu2" style="border: solid;width:100px;">Menu option2</div>
<div class="Menu3" style="border: solid;width:100px;">Menu option3</div>
<div class="loader loader-active"></div>