preloading image question

rickle42

New Member
Messages
59
Reaction score
0
Points
0
Hi,
If i preload images like this:
<script language="javascript" type="text/javascript">
<!--
if (document.images)
{
pica= new Image(100,100);
pica.src="cline3.gif";
picb= new Image(100,100);
picb.src="image0031.jpg";
picc= new Image(100,100);
picc.src="image007.jpg";
}</script>

Does it matter if the pics are 400x400. What parameters should i pass to Image(w,h)?
Do I need any at all?
Should they be the exact size of pic?

THX
 

DarkDragonLord

New Member
Messages
782
Reaction score
0
Points
0
i use this JS

Code:
function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; 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];}}
}

then just add the js and the image name at onLoad of Body
HTML:
<script type='text/javascript' src='scripts/js/loadimg.js'></script>

<body onLoad="MM_preloadImages('images/header.gif','images/xx.gif')">


maybe this one is better than yours since dont need to declare the width/height
 

Slothie

New Member
Messages
1,429
Reaction score
0
Points
0
You should have to specify width and height in a preloader. It justs loads the image first so the site will look right later.


The dimensions should be stated in th HTML
 

nightscream

New Member
Messages
948
Reaction score
0
Points
0
just do this
Code:
if (document.images)
{
pica= new Image;
pica.src="cline3.gif";
picb= new Image;
picb.src="image0031.jpg";
picc= new Image;
picc.src="image007.jpg";
}
 

rickle42

New Member
Messages
59
Reaction score
0
Points
0
Nightscream, I see your point. I was thinking it would just default to pic size cause it worked right with (100,100) for all of the pics, didnt know you could leave out the () though thx... I think I will use DDL's method though. Looks like less code by far for using a lot of preloads at least.
 

nightscream

New Member
Messages
948
Reaction score
0
Points
0
well I think that's the javascript that dreamweavers uses :p Well it works as fine so it doens't mather where it comes from :p

ps: ddl sorry if i'm wrong if you made it yourself, I should apoligze but it was just looking like the dreamweaver code
 

DarkDragonLord

New Member
Messages
782
Reaction score
0
Points
0
well I think that's the javascript that dreamweavers uses :p Well it works as fine so it doens't mather where it comes from :p

ps: ddl sorry if i'm wrong if you made it yourself, I should apoligze but it was just looking like the dreamweaver code

Nope, i didnt made, but i didnt got from dreamweaver too. :S
In the JS i have, got other functions like change images and others, so i just copied the preload he wanted :D
 
Top