Twinkie
Banned
- Messages
- 1,389
- Reaction score
- 12
- Points
- 0
I have a school project where I decided to make a web site quiz on book 10 of the odyssey. I like to do a nice job, so I threw some image fading effects and interactivity, but it's having some errors I don't have the time to fix! Why is this function freezing in the middle of the image preload (sometimes, not sure in what circumstances)?? ='(
Assuming that the variable quiz is an xml document, and that I am sure the loading bar ends at 100%, whats wrong with it?
Also, if you go through the quiz, the left image fades into the previous image and then switches to the next image in just one question. Quite an odd error because both groups of images are treated the same, and the error is consistent in IE 7 with different images. Any ideas please?
PS: It's due tomorrow so thanks for your help
Edit:
Thanks anyways... I can't close the thread.
Code:
var c = 0, b = 0, t;
function ImagePreload() {
var total = (quiz.getElementsByTagName("img1").length) + (quiz.getElementsByTagName("img2").length);
$("loading").innerHTML = "Loading "+ Math.round(100*((c+b)/total)) + "%";
if (quiz.getElementsByTagName("img1").length > c) {
var image1 = new Image();
image1.onabort=ImagePreload;
image1.onload=ImagePreload;
image1.src = quiz.getElementsByTagName("img1")[c++].childNodes[0].nodeValue;
} else if (quiz.getElementsByTagName("img2").length > b) {
var image2 = new Image();
image2.onabort=ImagePreload;
image2.onload=ImagePreload;
image2.src = quiz.getElementsByTagName("img2")[b++].childNodes[0].nodeValue;
} else {
$("loading").style.display="none";
NextQuestion();
return false;
}
return false;
}
Also, if you go through the quiz, the left image fades into the previous image and then switches to the next image in just one question. Quite an odd error because both groups of images are treated the same, and the error is consistent in IE 7 with different images. Any ideas please?
PS: It's due tomorrow so thanks for your help
Edit:
Thanks anyways... I can't close the thread.
Last edited: