There are a lot of ways in which we can show a loading
document.readyState property. When the value of this property changes, a
readystatechange event fires on the document object.
document.readyState property can return these three string values:
loading: when the document is still loading.
interactive: when the document has finished loading but sub-resources such as stylesheets, images and frames are still loading.
complete: when the document and all sub-resources have finished loading.
readystatechange event fires and our function executes. If the document is not yet loaded then the body should remain hidden from the user, only the loader should be visible. Once the page has completely loaded we set loader’s display to none and we make the body visible.
To see the code in action, you need to follow these simple steps:
Step 1: Copy and paste the example code from above in a text editor and save it with .html extension.
Step 2: Open the .html file you saved then open your browser’s developer tool, go to the networks tab and set throttling to Slow 3G. Here’s a GIF to show you how to do it:
Step 3: Reload the page using ctrl + f5. Here’s how the final output looks like:
- How to load jQuery code after loading the page?
- How to display search result of another page on same page using ajax in JSP?
- How to pass form variables from one page to other page in PHP ?
- How to redirect a page to another page in HTML ?
- What is Lazy Loading?
- Ways To Reduce The Loading Time Of Your Website | Set 2
- Loading Excel spreadsheet as pandas DataFrame
- Ways To Reduce The Loading Time Of Website | Set 1
- ES6 | Page Printing
- ES6 | Page Redirect
- CSS | @page rule
- Refresh a page using PHP
- How to add API function to a simple PHP Page ?
- CSS page-break-before Property
- CSS | page-break-after Property
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to email@example.com. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.