472,780 Members | 2,141 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

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

Preload Images. Please, help me out. Thank You.

Hello,

I think to preload an image I should us something like:

img = new Image();
img.src = 'images/img.jpg';

Could someone tell me how to create a loop which would preload a list
of images?
Something like:

ImagesFolder = '...';
ImagesNames = '...';

For i = 0 to ImagesNames.Count
img = new Image();
img.src = imagesFolder + imagesNames(i)
End

Is this a good approach?
Could someone tell me the javascript code for this?
I am not very confortable with javascript.

Thank You,
Miguel

Nov 25 '06 #1
4 1673
shapper escreveu:
Is this a good approach?
Could someone tell me the javascript code for this?
I am not very confortable with javascript.
Take a look if this helps: <URL:http://jsfromhell.com/classes/preloader>
--
Jonas Raoni Soares Silva
http://www.jsfromhell.com
Nov 25 '06 #2
shapper wrote:
Hello,

I think to preload an image I should us something like:

img = new Image();
img.src = 'images/img.jpg';

Could someone tell me how to create a loop which would preload a list
of images?
Something like:

ImagesFolder = '...';
ImagesNames = '...';

For i = 0 to ImagesNames.Count
img = new Image();
img.src = imagesFolder + imagesNames(i)
End
imgs=["a.gif","../b.gif","http://example.com/imgs/c.gif" ...],pics=[];
for(var i=0;i<imgs.length;i++){
pic[i]=new Image()
pic[i].src=imgs[i];
}

Something like that
Mick
>
Is this a good approach?
Could someone tell me the javascript code for this?
I am not very confortable with javascript.

Thank You,
Miguel
Nov 25 '06 #3


On 25 Nov., 18:31, mick white <m...@mickweb.comwrote:
shapper wrote:
Hello,
I think to preload an image I should us something like:
img = new Image();
img.src = 'images/img.jpg';
Could someone tell me how to create a loop which would preload a list
of images?
Something like:
ImagesFolder = '...';
ImagesNames = '...';
For i = 0 to ImagesNames.Count
img = new Image();
img.src = imagesFolder + imagesNames(i)
Endimgs=["a.gif","../b.gif","http://example.com/imgs/c.gif" ...],pics=[];
for(var i=0;i<imgs.length;i++){
pic[i]=new Image()
pic[i].src=imgs[i];

}Something like that
Mick
Is this a good approach?
Could someone tell me the javascript code for this?
I am not very confortable with javascript.
Thank You,
Miguel
Better create REAL images, means document.body.appendChild them to your
site and simply set display="none" or visibility="hidden", so they are
really preloaded. My experience with new Image() ... is bad, not all
browser preload them onload. Example

imgs=["a.gif","../b.gif","http://example.com/imgs/c.gif" ...],pics=[];
for(var i=0;i<imgs.length;i++){
// why make an image array, excepting you want get the images
explicitly. Important is, that the browser loads the image data.
var im = document.createElement('img'); // probably the same as new
Image(), I dont know.
im.src=imgs[i];
im.style.width = im.style.height = '0';
im.style.visibility = 'hidden';
// I am not sure if your browser loads them using display="none"
}

Andi

Nov 25 '06 #4
ASM
shapper a écrit :
I think to preload an image I should us something like:

img = new Image();
img.src = 'images/img.jpg';

Could someone tell me how to create a loop which would preload a list
of images?
Something like:

ImagesFolder = '...';
ImagesNames = '...';

For i = 0 to ImagesNames.Count
img = new Image();
img.src = imagesFolder + imagesNames(i)
End
imgs=["a.gif","../b.gif","http://example.com/imgs/c.gif" ...],pics=[];

function postLoad(k, max){
if(k<max) {
pic[k] = new Image();
pic[k].onload = function(){postLoad(k,max)};
pic[k].src = imgs[i];
k++;
}
}

onload = function(){ postLoad(0, imgs.length); };
--
Stephane Moriaux et son (moins) vieux Mac déjà dépassé
Stephane Moriaux and his (less) old Mac already out of date
Contact : http://stephane.moriaux.perso.wanadoo.fr/contact
ASM = Aimable Stéphane Moriaux = Amateur Sasseur Merdouilles
Nov 26 '06 #5

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

Similar topics

7
by: MALdito | last post by:
hi everybody let me say right from the start .. I´m not a coder ... "just" a designer! that said .. here is my question: I´m using dreamweaver´s built in preloader for a menu. it looks like...
3
by: Bob | last post by:
I usually use some "pre-load" code in my pages to preload graphics that will be swapped. But, I'm thinking that rather than the long, repetitive, once, for each graphic hardcoded stuff like this: ...
2
by: Albert Spencil | last post by:
I have tried several preload scripts found here; plus, some of my own. The only thing that works is the unsophisticated loading of those tiny images. The download consist of 100+ images amounting...
1
by: Stacey | last post by:
Hi, I'm hoping for a bit of advise-- I have a (relatively, from the point-of-view of this dilettante) complex script that attempts to preload certain images in order to trigger one of a series of...
5
by: roN | last post by:
Hi, I have following issue: I'm changing the css-style of a tab like following when the mouse is rolling over it: onMouseOver="this.className='frontbarOverIE'" and the css style looks like...
4
by: shapper | last post by:
Hello, I am working in Asp.Net 2.0 web sites and I need to preload some images in my master pages and in the pages that use those master pages. Could someone tell me how to do this? Thanks,...
9
by: shapper | last post by:
Hello, How can I preload a few images of a page javascript? Should I use CSS to do this? Is it even possible? Thanks, Miguel
2
by: matt9807 | last post by:
The following is a script that I have written that preloads images for an image gallery. The problem is that the images only preload in Safari, other browsers load each image when it is called. Any...
3
by: Revathi Balakrishnan | last post by:
Hi i have the used the below code to switch the button image on mouseover and mouseout. <html:button property="Button" value="Display" styleClass="displaybutton" ...
0
by: Rina0 | last post by:
Cybersecurity engineering is a specialized field that focuses on the design, development, and implementation of systems, processes, and technologies that protect against cyber threats and...
3
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 2 August 2023 starting at 18:00 UK time (6PM UTC+1) and finishing at about 19:15 (7.15PM) The start time is equivalent to 19:00 (7PM) in Central...
0
by: erikbower65 | last post by:
Using CodiumAI's pr-agent is simple and powerful. Follow these steps: 1. Install CodiumAI CLI: Ensure Node.js is installed, then run 'npm install -g codiumai' in the terminal. 2. Connect to...
0
linyimin
by: linyimin | last post by:
Spring Startup Analyzer generates an interactive Spring application startup report that lets you understand what contributes to the application startup time and helps to optimize it. Support for...
0
by: kcodez | last post by:
As a H5 game development enthusiast, I recently wrote a very interesting little game - Toy Claw ((http://claw.kjeek.com/))。Here I will summarize and share the development experience here, and hope it...
0
by: Taofi | last post by:
I try to insert a new record but the error message says the number of query names and destination fields are not the same This are my field names ID, Budgeted, Actual, Status and Differences ...
14
DJRhino1175
by: DJRhino1175 | last post by:
When I run this code I get an error, its Run-time error# 424 Object required...This is my first attempt at doing something like this. I test the entire code and it worked until I added this - If...
0
by: Rina0 | last post by:
I am looking for a Python code to find the longest common subsequence of two strings. I found this blog post that describes the length of longest common subsequence problem and provides a solution in...
0
by: Mushico | last post by:
How to calculate date of retirement from date of birth

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.