Does this make sense?

A

Adrian MacNair

Because it's not working...

I want a condition where if only the images are all preloaded then the slide
show will work:

<script type="text/javascript">
var imagesdone=false;
window.onload=loadimages;
function loadimages() {
var images=new Array();
for (var i=0;i<myImages.length;i++) {
images=new Image();
images.src=myImages;
}
imagesdone=true;
}
// This is an onClick event
function startslideshow() {
if (imagesdone) {
do slideshow stuff
} else {
alert('Sorry, images are not loaded for viewing yet')
}
}
</script>
 
R

Randy Webb

Adrian said:
Because it's not working...

I want a condition where if only the images are all preloaded then the slide
show will work:

<script type="text/javascript">
var imagesdone=false;
window.onload=loadimages;
function loadimages() {
var images=new Array();
for (var i=0;i<myImages.length;i++) {
images=new Image();
images.src=myImages;
}
imagesdone=true;


That doesn't ensure the images are loaded, it only ensures that the
request was made for the image. The imagesdone is set to true before the
first image is even downloaded.


Have the images preloaded while the page loads, then the window.onload
won't fire until they are loaded. Another possibility is to add an
onload to each preloaded image that will call a function that
incremements a counter, then checks the counter. If the counter matches
myImages.length then they are all loaded and it will set imagesdone to true.
 
A

alu

Another possibility is to write the images into the page but not display
them; the <body> onload would fire only when all images are loaded.
-alu


<script type="text/javascript">

var imagesdone=false;

// This is an onClick event
function startslideshow() {
if (imagesdone) {
alert("do slide show") ;
} else {
alert('Sorry, images are not loaded for viewing yet')
}
}
</script>


</head>
<body onload="imagesdone=true;">

<a href="#" onclick="startslideshow()">test images loaded?</a>

<script>
for (var im=0;im<myImages.length;im++) {
document.write('<img src="'+myImages[im]+'" alt=""
style="display:none">')
}

</script>

</body>
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,994
Messages
2,570,223
Members
46,810
Latest member
Kassie0918

Latest Threads

Top