How to add loading GIF to this JS function?

Hi,

I have this short JS function called 'init' that loads images from an array into a <div> one at a time, hiding them. It then creates a transparent sheet to go over the images for mouse events, and finally displays one of the images. I would like to have a loading gif play until the everything is done and the image is displayed. Would be grateful for any help on how to get this done -- thank you!
function init() {
  title = document.getElementById('title');
  sketchUpObj = document.getElementById('sketchUpObj');
  imageCount = imageFileNameArray.length;

  // load up the imageArray with the sketchUp images
  for (i = 0; i < imageCount; i++) {
    sketchUpImageArray[i] = new Image();
    sketchUpImageArray[i].src = imageFileNameArray[i];
    sketchUpImageArray[i].className = 'sketchUpImage';
    hide(sketchUpImageArray[i]);
    document.getElementById('sketchUpObj').appendChild(sketchUpImageArray[i]);
  }
//create a transparent sheet over the images so that the mouseevents go it it
  var sheet = document.createElement("DIV");
  document.getElementById('sketchUpObj').appendChild(sheet);
  sheet.id = "sheet";
  sheet.onmousemove = handleRotate;
  sheet.onmousedown = handleMouseDown;
  sheet.onmouseup = handleMouseUp;
  sheet.onmouseout = handleMouseUp;
  setOpacity(sheet, 0.0);

  currentPos = imageCount-1
  show(sketchUpImageArray[currentPos]);
}

Open in new window

LVL 6
andreyman3d2kAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

leakim971PluritechnicianCommented:
check this test page : http://jsfiddle.net/4K4Lb/


var imageFileNameArray = ["http://www.nfsource.net/files/images/12-03-11/SHIFT2_Unleashed_LOTUS_ELISE_111R_01.jpg", "http://www.nfsource.net/files/images/12-03-11/SHIFT2_Unleashed_LOTUS_ELISE_111R_02.jpg", "http://www.nfsource.net/files/images/12-03-11/SHIFT2_Unleashed_LOTUS_ELISE_111R_03.jpg"];
var c = 0;

function init() {
    title = document.getElementById('title');
    sketchUpObj = document.getElementById('sketchUpObj');
    imageCount = imageFileNameArray.length;
    for (i = 0; i < imageCount; i++) {
        var sketchUpImage = new Image();
        sketchUpImage.src = imageFileNameArray[i];
        sketchUpImage.className = 'sketchUpImage';
        sketchUpImage.onload = function() { 
            if(++c==1) this.style.display = "block";
            else if(c==imageFileNameArray.length) {
                document.getElementById("loading").style.display = "none";
                alert("all pics loaded!");
            }
        };
        //hide(sketchUpImageArray[i]);
        document.getElementById('sketchUpObj').appendChild(sketchUpImage);
    }
}

window.onload = function() {
    init();
}

Open in new window

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
andreyman3d2kAuthor Commented:
Awesome help, thank you!
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
JavaScript

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.