To incorporate a loading indicator in your single page application (SPA), you can insert a loading sign within the index.html
file inside a div that is typically labeled as root
or app
. This loading indicator will automatically disappear once the entire application has been fully loaded. For instance, include the following styling inside the head
section of your index.html
file:
<style>
.loading {
display: inline-block;
width: 30px;
height: 30px;
border: 2px solid rgba(0,0,0,.2 );
border-radius: 50%;
border-top-color: rgba(0,0,0,.4 );
animation: spin 1s ease-in-out infinite;
-webkit-animation: spin 1s ease-in-out infinite;
left: calc(50%);
top: calc(50%);
position: fixed;
z-index: 1;
}
@keyframes spin {
to { -webkit-transform: rotate(360deg); }
}
@-webkit-keyframes spin {
to { -webkit-transform: rotate(360deg); }
}
</style>
Next, place the following code within the body tag:
<body>
<noscript>
You need to enable JavaScript to run this app.
</noscript>
<div id="app">
<div class="loading"></div>
</div>
</body>