The easiest way is to create a spinner
<section id="loading">
<div id="loading-content"></div>
</section>
.loading {
z-index: 20;
position: absolute;
top: 0;
left:-5px;
width: 100%;
height: 100%;
background-color: rgba(0,0,0,0.4);
}
.loading-content {
position: absolute;
border: 16px solid #f3f3f3; /* Light grey */
border-top: 16px solid #3498db; /* Blue */
border-radius: 50%;
width: 50px;
height: 50px;
top: 40%;
left:35%;
animation: spin 2s linear infinite;
}
@keyframes spin {
0% { transform: rotate(0deg); }
100% { transform: rotate(360deg); }
}
function showLoading() {
document.querySelector('#loading').classList.add('loading');
document.querySelector('#loading-content').classList.add('loading-content');
}
function hideLoading() {
document.querySelector('#loading').classList.remove('loading');
document.querySelector('#loading-content').classList.remove('loading-content');
}