Note that there are some explanatory texts on larger screens.

plurals
  1. PORemoving or skipping an image from an Image array if it fails to load?
    primarykey
    data
    text
    <p>I am trying to create a simple animation viewer for a sequence of map images using Javascript. I first load the images into a global array like this</p> <pre><code>while( datetime &lt;= endDatetime) { var fname = getImgFnameFromDate(datetime); var imgAdd = new Image(); imgAdd.src = fname; imgStore.push(imgAdd); datetime.setMinutes(datetime.getMinutes() + 15); } </code></pre> <p>and then loop through them with a short wait between each image.</p> <pre><code>function iter() { ++imgIndex; if (loopFlag) imgIndex = imgIndex % imgStore.length; document.getElementById("map").src=imgStore[imgIndex].src; } </code></pre> <p>Now, the maps are made in near real time and occasionally some will be missing. The file fails to load giving instead a broken link image in the midst of the animation. I would like to simply skip an image that did not load, either by skipping over it or removing it from the array.</p> <p>I have tried using the image width attribute as a proxy for 'isLoaded' i.e. something like</p> <pre><code>function iter() { ++imgIndex; if (loopFlag) imgIndex = imgIndex % imgStore.length; document.getElementById("map").src=imgStore[imgIndex].src; if (imgStore[imgIndex].width == 0) iter(); } </code></pre> <p>However this is unreliable and often leads to an infinite loop as it appears to trigger before the images have had a chance to load.</p> <p>I have tried specifying an onError function for the images, but I can't work out what that function should do. I really want some kind of isLoaded attribute, rather than an event. Maybe I'm going about this the wrong way?</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.
    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