Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to show a spinner while loading an image via JavaScript
    primarykey
    data
    text
    <p>I'm currently working on a web application which has a page which displays a single chart (a .png image). On another part of this page there are a set of links which, when clicked, the entire page reloads and looks exactly the same as before except for the chart in the middle of the page.</p> <p>What I want to do is when a link is clicked on a page just the chart on the page is changed. This will speed things up tremendously as the page is roughly 100kb large, and don't really want to reload the entire page just to display this. </p> <p>I've been doing this via JavaScript, which works so far, using the following code</p> <pre><code>document.getElementById('chart').src = '/charts/10.png'; </code></pre> <p>The problem is that when the user clicks on the link, it may take a couple of seconds before the chart changes. This makes the user think that their click hasn't done anything, or that the system is slow to respond.</p> <p>What I want to happen is display a spinner / throbber / status indicator, in place of where the image is while it is loading, so when the user clicks the link they know at least the system has taken their input and is doing something about it. </p> <p>I've tried a few suggestions, even using a psudo time out to show a spinner, and then flick back to the image. </p> <p>A good suggestion I've had is to use the following</p> <pre><code>&lt;img src="/charts/10.png" lowsrc="/spinner.gif"/&gt; </code></pre> <p>Which would be ideal, except the spinner is significantly smaller than the chart which is being displayed.</p> <p>Any other ideas?</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload