I have a section on our website that loads quite slowly as it's doing some intensive calls.
Any idea how I can get a div
to say something similar to "loading" to show while the page prepares itself and then vanish when everything is ready?
相关问题
- Views base64 encoded blob in HTML with PHP
- Is there a limit to how many levels you can nest i
- How to toggle on Order in ReactJS
- How to fix IE ClearType + jQuery opacity problem i
- void before promise syntax
Create a
<div>
element that contains your loading message, give the<div>
an ID, and then when your content has finished loading, hide the<div>
:...or in plain JavaScript:
I have another below simple solution for this which perfectly worked for me.
First of all, create a CSS with name Lockon class which is transparent overlay along with loading GIF as shown below
Now we need to create our div with this class which cover entire page as an overlay whenever the page is getting loaded
Now we need to hide this cover screen whenever the page is ready and so that we can restrict the user from clicking/firing any event until the page is ready
Above solution will be fine whenever the page is loading.
Now the question is after the page is loaded, whenever we click a button or an event which will take a long time, we need to show this in the client click event as shown below
That means when we click this print button (which will take a long time to give the report) it will show our cover screen with GIF which gives result and once the page is ready above windows on load function will fire and which hide the cover screen once the screen is fully loaded.
JS:
CSS:
HTML:
Page loading image with simplest fadeout effect created in JS:
This script will add a div that covers the entire screen as the page loads. It will show a CSS-only loading spinner automatically. It will wait until the window (not the document) finishes loading, then it will wait an optional extra few seconds.
Place the script below at the bottom of the body.
CSS loader code from https://projects.lukehaas.me/css-loaders
Based on @mehyaa answer, but much shorter:
HTML (right after
<body>
):CSS:
Javascript (jQuery, since I'm already using it):
Default the contents to
display:none
and then have an event handler that sets it todisplay:block
or similar after it's fully loaded. Then have a div that's set todisplay:block
with "Loading" in it, and set it todisplay:none
in the same event handler as before.