Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7672949
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T16:24:04+00:00 2026-05-31T16:24:04+00:00

I am trying to create a simple animation viewer for a sequence of map

  • 0

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

while( datetime <= endDatetime) 
{
   var fname = getImgFnameFromDate(datetime);
   var imgAdd = new Image();
   imgAdd.src = fname;
   imgStore.push(imgAdd);   
   datetime.setMinutes(datetime.getMinutes() + 15);
}

and then loop through them with a short wait between each image.

function iter()
{         
   ++imgIndex;
   if (loopFlag) imgIndex = imgIndex % imgStore.length;
   document.getElementById("map").src=imgStore[imgIndex].src;
}

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.

I have tried using the image width attribute as a proxy for ‘isLoaded’ i.e. something like

function iter()
{         
   ++imgIndex;
   if (loopFlag) imgIndex = imgIndex % imgStore.length;
   document.getElementById("map").src=imgStore[imgIndex].src;
   if (imgStore[imgIndex].width == 0) iter();
}

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.

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?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-31T16:24:05+00:00Added an answer on May 31, 2026 at 4:24 pm

    You can set a flag on the image object when it loads and test that flag later:

    var fname = getImgFnameFromDate(datetime);
    var imgAdd = new Image();
    imgAdd.onload = function() {
        this.myLoadFlag = true;
    }
    imgAdd.src = fname;
    imgStore.push(imgAdd);   
    

    Then elsewhere, you can check to see if the image has been loaded yet:

    if (imgStore[imgIndex].myLoadFlag) {
       // image has been loaded
    }
    

    When using an onload handler, just make sure that you set it before you set the .src property otherwise, there are some cases in some browsers where you will miss the onload event if the image is already in the browser cache.


    An alternate approach (perhaps simpler to use) would be to have a second array that only contains loaded images and your main code only uses that:

    // place we first put images, they go into imgStore only when actually loaded
    var imgPending = [];
    
    var fname = getImgFnameFromDate(datetime);
    var imgAdd = new Image();
    imgAdd.onload = function() {
        imgStore.push(imgAdd);    // now that it's loaded, add it to the images we're using
    }
    imgAdd.src = fname;
    imgPending.push(imgAdd);   
    

    Then, your code that uses imgStore will only ever see images that are actually loaded. One downside to this is that images go into imgStore in load order, not necessarily in the order that you request them so the order this way could be different than your old way.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to create a simple animation in which the background-color slides into place.
I'm trying to create a very simple keyframe animation, whereby a graphic Rotates from
Im trying to create a simple pan and zoom app using silverlight 4, but
I am trying to create a simple dialog in MFC using Visual C++. My
I'm trying to create a simple toggling sidebar using jquery, where it expands and
I am trying to create a simple mouseover effect using a combination of mouseover,
I'm trying to create a simple database table using the PHP MySQL query Create
I am trying to create a simple (I think) animation effect based on a
I'm trying to create a simple animation in which a block of text drops
I'm trying to create a really simple animation that moves along an absolutely positioned

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.