View Full Version : percentage loader goes past 100%!?

Aug 16th, 2002, 08:33 PM
I have a script for an image preloader. It works fine exept the percentage counter goes past 100%. When I call list the files in the array in this format "name.jpg" the counter works but it can locate the images. When I call them out in this format "folder/images/name.jpg" it finds the image, but the counter continues past 100%. Copy of script below. This forum is so helpful - thank you in advance for any replies to my ?.

var pics = new Array("DBCpublic/images to use/horiz linegrey.jpg");

var url = "DBCpublic/home.htm";

var doConfirm = true;

var canSkip = true;

var imgObjs = new Array(pics.length);
var loaded = 0;
var total = pics.length;
var cPercent = 0;

var barLayer = null;
var percentLayer = null;
var statLayer = null;
var doneMsgLayer = null;

function getLayer(layerID) {
if (document.getElementById)
return document.getElementById(layerID);
else if (document.all)
return document.all[layerID];
return null;

function updateBar() {
statLayer.innerHTML = "<font face=\"Arial\" color=\"#cccccc\" size=\"2\">" +loaded+ "/" +total+ "</font>";
var percent = Math.round(loaded/total * 100);
if (cPercent != percent)
cPercent = percent;
barLayer.style.width = (cPercent*3.5) +"px";
percentLayer.innerHTML = "<font color=\"#cccc99\"><B>" +cPercent+ "%</B></font>";
if (loaded == total)
doneMsgLayer.innerHTML = "<a href=\"javascript:done()\"><font face=\"Arial\" color=\"#cccc99\" size=\"2\">enter site (click here)</font></a>";
if (doConfirm && confirm("files have loaded, continue to next page?"))

function startLoading() {
if (document.getElementById || document.all)
barLayer = getLayer("bar");
percentLayer = getLayer("percent");
statLayer = getLayer("stat");
doneMsgLayer = getLayer("doneMsg");
if (canSkip)
doneMsgLayer.innerHTML = "<a href=\"javascript:done()\"><font color=\"#cccc99\" size=\"2\" face=\"Arial\">skip pre-loading</font></a>";
for (i=0; i<pics.length; i++)
imgObjs[i] = new Image();
imgObjs[i].onload = imgLoaded;
imgObjs[i].onerror = imgFailed;
imgObjs[i].src = pics[i];
alert("You are running an older browser which is not compatible with this preloading script. Please update your browser.\n\nProgram is skipping preloading.");

function done() {

function imgFailed() {
alert("The following image failed to load, :\n" +this.src+ "\nPlease contact the webmaster to missing link. The program will skip this file now.");

function imgLoaded() {

Aug 16th, 2002, 09:19 PM
have i done something wrong? What does the black dot on my envelope icon mean? Was my question offensive?

Aug 16th, 2002, 09:34 PM
It means you've posted something in that thread. Only you see that, well now me too.

I didn't try the script, but try floor() instead or round()