473,382 Members | 1,225 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,382 software developers and data experts.

Does this make sense?

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[i]=new Image();
images[i].src=myImages[i];
}
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>
Jul 23 '05 #1
2 980
Adrian MacNair wrote:
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[i]=new Image();
images[i].src=myImages[i];
}
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.
}
// This is an onClick event
function startslideshow() {
if (imagesdone) {
do slideshow stuff
} else {
alert('Sorry, images are not loaded for viewing yet')
}
}
</script>

--
Randy
comp.lang.javascript FAQ - http://jibbering.com/faq & newsgroup weekly
Jul 23 '05 #2
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>
Jul 23 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

37
by: Curt | last post by:
If this is the complete program (ie, the address of the const is never taken, only its value used) is it likely the compiler will allocate ram for constantA or constantB? Or simply substitute the...
3
by: Jukka K. Korpela | last post by:
I have noticed that the meaning of visibility: collapse has been discussed on different forums, but with no consensus on what it really means. Besides, implementations differ. The specification...
0
by: mike | last post by:
regards: Does the following programming architecture make sense? http://www.wretch.cc/album/show.php?i=otp&b=1&f=1111993473&p=2 ...
10
by: DataBard007 | last post by:
Hello Access Gurus: I use Win98SE and Access97. I just built a simple Access97 application which holds all contact information for my personal contacts, such as first name, last name, address,...
1
by: mikeotp | last post by:
Does the statement make sense? Meaning of “program” is to setup *.h(header檔) and to edit a main file to be a program exit. The main file includes all of the“*.h” files I edited before....
3
by: **Developer** | last post by:
I have a usercontrol that contains two pictureboxes One is on top of the other. The bottom one is the parent of the top one. The top one is transparent. I invalidate the top one often
3
by: electrician | last post by:
Yes, no GOTO. This is a major blunder on part of the creators of these tools. GOTO gives the programmer the absolute control over the program. Yes, no matter what, a GOTO sends the program to...
33
by: dragoncoder | last post by:
Hi all, Does the following code invoke undefined behaviour ? $ cat a1.cc #include <iostream> #include <limits> int main() { int a = INT_MAX/2;
48
by: Jimmy | last post by:
thanks to everyone that helped, unfortunately the code samples people gave me don't work. here is what i have so far: <% Dim oConn, oRS, randNum Randomize() randNum = (CInt(1000 * Rnd) + 1) *...
2
by: puzzlecracker | last post by:
I have never seen this in practice and interested in its pros, or ever existential (another words, standardized) possibility? Thanks, Sasha
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.