473,699 Members | 2,933 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Help with a Simple Question

Hi,

This is a newbie's question. I want to preload 4 images and only when
all 4 images has been loaded into browser's cache, I want to start a
slideshow() function. If images are not completed loaded into cache,
the slideshow doesn't look very nice.

I am not sure how/when to call the slideshow() function to make sure it
starts after the preload has been completed.

Thanks in advance for your help!

Terry

*************** *************** *************** *************** *
<head>
<script language="JavaS cript" type="text/JavaScript">
<!--
function MM_preloadImage s() {
var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
var i,j=d.MM_p.leng th,a=MM_preload Images.argument s; for(i=0; i
<a.length; i++)
if (a[i].indexOf("#")!= 0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a
[i];}}
}

function slideshow() {

.....

}

//-->
</script>
</head>

<body onload="MM_prel oadImages('01.j pg','02.jpg','0 3.jpg','04.jpg' )">
</body>
</html>
Jul 20 '05 #1
16 2894
In article <MP************ ************@ne ws.tc.umn.edu>, Terry
<go************ **@REMOVE.yahoo .com> writes:
This is a newbie's question. I want to preload 4 images and only when
all 4 images has been loaded into browser's cache, I want to start a
slideshow() function. If images are not completed loaded into cache,
the slideshow doesn't look very nice.

I am not sure how/when to call the slideshow() function to make sure it
starts after the preload has been completed.


load it via the window.onload or in the body tag:

window.onload = slideshow;

in the script section, or:

<body onload="slidesh ow()">

The page will not be considered "loaded" until the images are loaded as well.
--
Randy
Jul 20 '05 #2

load it via the window.onload or in the body tag:

window.onload = slideshow;

in the script section, or:

<body onload="slidesh ow()">

The page will not be considered "loaded" until the images are loaded as well.


Randy,

I did the above. However, the slideshow starts before all the images
are loaded.

Terry
Jul 20 '05 #3
Terry wrote:
load it via the window.onload or in the body tag:

window.onlo ad = slideshow;

in the script section, or:

<body onload="slidesh ow()">

The page will not be considered "loaded" until the images are loaded as well.

Randy,

I did the above. However, the slideshow starts before all the images
are loaded.

Terry


<img src="image1.jpg " width="1" height="1">
<img src="image2.jpg " width="1" height="1">
<img src="image3.jpg " width="1" height="1">
<img src="image4.jpg " width="1" height="1">

and so on for each image. Then use the body's onload or window.onload to
start the slideshow.

Or, something is wrong with your preloading script. Post a URL to a
sample page if you can't get it working.

Jul 20 '05 #4
<img src="image1.jpg " width="1" height="1">
<img src="image2.jpg " width="1" height="1">
<img src="image3.jpg " width="1" height="1">
<img src="image4.jpg " width="1" height="1">

and so on for each image. Then use the body's onload or window.onload to
start the slideshow.

Or, something is wrong with your preloading script. Post a URL to a
sample page if you can't get it working.


Hi Randy, Thanks for your help!

http://free.hostdepartment.com/j/javashop/

Please take a look of the link if you have a minute. It has no problem
with fast internet connection. However, over 56k modem, I can see that
the slide show has started while down at the status bar, it says that X
number of images remained to be downloaded.

Terry
Jul 20 '05 #5
Randy,

http://free.hostdepartment.com/j/jav...reload_bar.htm

Can you take a look of this link as well? The slide show starts before
the image loading bar gets 100%.

I was wonder if there is way to call a function after the preloading
complete. I am not sure where to stick in the nextAd() -- the slideshow
function inside the image loading function.

Thanks again!

Terry
Jul 20 '05 #6
Terry wrote:
<img src="image1.jpg " width="1" height="1">
<img src="image2.jpg " width="1" height="1">
<img src="image3.jpg " width="1" height="1">
<img src="image4.jpg " width="1" height="1">

and so on for each image. Then use the body's onload or window.onload to
start the slideshow.

Or, something is wrong with your preloading script. Post a URL to a
sample page if you can't get it working.

Hi Randy, Thanks for your help!

http://free.hostdepartment.com/j/javashop/

Please take a look of the link if you have a minute. It has no problem
with fast internet connection. However, over 56k modem, I can see that
the slide show has started while down at the status bar, it says that X
number of images remained to be downloaded.


Thats because your preload routing happens after the page has loaded.

<body onload="MM_prel oadImages(snipp ed for brevity), nextAd()">

Page loads.
Preload routine starts, images start downloading.
nextAd() starts.

If you are wanting to ensure that the images load before the routine
starts, then remove the preload from the onload, and load them during
page processing.

--
Randy

Jul 20 '05 #7
Thats because your preload routing happens after the page has loaded.

<body onload="MM_prel oadImages(snipp ed for brevity), nextAd()">

Page loads.
Preload routine starts, images start downloading.
nextAd() starts.

If you are wanting to ensure that the images load before the routine
starts, then remove the preload from the onload, and load them during
page processing.


Thanks again Randy! It makes sense. Just to make sure I understand.
So if I put the following "preload" script in the <head> or <body> of a
page, the 2 images get loaded before any "onload" routines start?

During "page processing", do all the scripts embedded in <head> and
<body> get executed before "onload" routines?

<head>
<script type="text/javascript" language="JavaS cript">

var bannerAD=new Array("images/01.jpg","images/02.jpg");

var preloadedimages =new Array();
for (i=0;i<bannerAD .length;i++){
preloadedimages[i]=new Image();
preloadedimages[i].src=bannerAD[i];
}
</script>
</head>
Jul 20 '05 #8
Terry wrote:
Thats because your preload routing happens after the page has loaded.

<body onload="MM_prel oadImages(snipp ed for brevity), nextAd()">

Page loads.
Preload routine starts, images start downloading.
nextAd() starts.

If you are wanting to ensure that the images load before the routine
starts, then remove the preload from the onload, and load them during
page processing.

Thanks again Randy! It makes sense. Just to make sure I understand.
So if I put the following "preload" script in the <head> or <body> of a
page, the 2 images get loaded before any "onload" routines start?


Yes.
During "page processing", do all the scripts embedded in <head> and
<body> get executed before "onload" routines?
Depends on what they do. But for the most part, yes.
<head>
<script type="text/javascript" language="JavaS cript">

var bannerAD=new Array("images/01.jpg","images/02.jpg");

var preloadedimages =new Array();
for (i=0;i<bannerAD .length;i++){
preloadedimages[i]=new Image();
preloadedimages[i].src=bannerAD[i];
}
</script>
</head>


In theory it does. In practice, I haven't seen a situation where that
doesn't work. Doesn't mean there isn't one though.

P.S. The language attribute is not needed, type="text/javascript" is
sufficient on its own.

--
Randy

Jul 20 '05 #9
Randy,

Thanks so much for your help! Here is a slightly off-subject question.
When I load the page, it seemed to me that images were loaded sequentially
based on their names. In other words, 01.jpg is loaded earlier than
logo.jpg. Am I imagining this or is it the order in which the images are
loaded onto a page?

Terry
Jul 20 '05 #10

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

Similar topics

2
1843
by: Carolyn Gill | last post by:
I have already created an asp login/database for a learning/quiz section on a small site. There will be multiple quizzes through the site and what I need now would be help: tutorials or advice that a complete novice can understand/follow to create the following: A small simple quiz--for now each has just one question with 5 multi-choice buttons. On submit should send the answer to A) a database (using access for now) to track scoring...
6
2767
by: max reason | last post by:
A method in one of my classes needs to call one of 256 other methods in the same class based on an unsigned 8-bit value (0x00 to 0xFF). How is this done? Everything I try generates errors. Something this basic can't be so difficult (or impossible) - can it? Thanks. The following roughly shows what I want: class simple { public:
9
2933
by: sk | last post by:
I have an applicaton in which I collect data for different parameters for a set of devices. The data are entered into a single table, each set of name, value pairs time-stamped and associated with a device. The definition of the table is as follows: CREATE TABLE devicedata ( device_id int NOT NULL REFERENCES devices(id), -- id in the device
2
1465
by: not | last post by:
Hello All, I am trying to develop a relatively simple self-quiz form in javascript, but I'm having no luck getting it to work. What I am looking for is a script that allow the user to select one of three answers for each question, and automatically assign a value to their answer ("never"=0, "sometimes"=1, "always"=2). There would be anywhere from ten to thirty questions. I want the script to calculate the running total, and then...
1
3428
by: Proteus | last post by:
Any help appreciated on a small perl project I need to write for educator/teaching purposes. I have not programmed perl for some time, need to get up to speed, maybe some kind souls hrere will help me on this project? It looks to be a simple project, and I will start relearning pearl, but any help appreciated! I need to read and parse a simple text file (INPUT) containing multiple choice quiz questions (with titles) and answers, and...
11
1422
by: MOOVBUFF | last post by:
I've been looking (wasting my time) for simple solutions such as Updating a database in VS 2005 and all I get is either no answer or another question. Obviously the people in the newsgroup can't read. At least the people in the VB 6.0 newsgroup answer without throwing in an insult. Good Ridance!
13
2144
by: sd00 | last post by:
Hi all, can someone give me some coding help with a problem that *should* be really simple, yet I'm struggling with. I need the difference between 2 times (Target / Actual) However, these times will fall somewhere between a Start & End time Further more, there will be Break & Lunch times between Start & End. Example... Start 08:00 Break start 10:30
8
2080
by: pamelafluente | last post by:
I am beginning aspNet, I know well win apps. Need a simple and schematic code example to start work. This is what I need to accomplish: ---------------------- Given button and a TextBox on a web form when one presses the button on the web form on a client pc, the sql query which is contained in the text box is sent to a vb net application on a server pc. The win application sends the query to the database, collects the results,
16
2531
by: pamelafluente | last post by:
I am still working with no success on that client/server problem. I need your help. I will submit simplified versions of my problem so we can see clearly what is going on. My model: A client uses IE to talk with a server. The user on the client (IE) sees an ASP net page containing a TextBox. He can write some text in this text box and push a submit button.
0
5570
by: gunimpi | last post by:
http://www.vbforums.com/showthread.php?p=2745431#post2745431 ******************************************************** VB6 OR VBA & Webbrowser DOM Tiny $50 Mini Project Programmer help wanted ******************************************************** For this teeny job, please refer to: http://feeds.reddit.com/feed/8fu/?o=25
0
9187
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9053
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8936
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8894
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7776
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
4390
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4636
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3071
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
2360
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.