Flash Games
 FAQ   Search   Memberlist   Usergroups   Register  Profile   Log in to check your private messages   Log in 


Preload images



 

Post new topic   Reply to topic  
   DEVPPL Forum Index -> JavaScript Forum
View previous topic :: View next topic  
Author Message
ranosb



Joined: 15 Apr 2008
Posts: 14

PostPosted: Fri Apr 18, 2008 7:01 pm    Post subject: Preload images Reply with quote

Is there not a better preload script, this does nothing. My page sometimes shows the images, sometimes not.
Where do I call this function?

function preloadit() {

myimg1 = new Image(32,32);
myimg2 = new Image(32,32);
myimg1.src = “32x32.ico”;
myimg2.src = “checkbox.png”;
}

preloadit()
Back to top
View user's profile Send private message
webmaster
Site Admin


Joined: 17 Aug 2004
Posts: 3642
Location: Sweden

PostPosted: Sat Apr 19, 2008 12:20 am    Post subject: Re: Preload images Reply with quote

You can easily do it with CSS just like this:
Code:
<img src="image1.jpg" alt="" style="display:none;" />
<img src="image2.jpg" alt="" style="display:none;" />
<img src="image3.jpg" alt="" style="display:none;" />
Back to top
View user's profile Send private message Visit poster's website
rangana
500+ Club


Joined: 27 Feb 2008
Posts: 629
Location: Cebu City Philippines

PostPosted: Sat Apr 19, 2008 12:43 am    Post subject: Re: Preload images Reply with quote

Call that function during onload Wink

...And as what webmaster says, CSS can do it for you...inline display:none; would'nt be ideal if you had a number of images...give each image a class, then use display:none; in your CSS declaration

...Then decide as to when you want the image be displayed...do get back if you're still stumped Wink
Back to top
View user's profile Send private message Yahoo Messenger
ranosb



Joined: 15 Apr 2008
Posts: 14

PostPosted: Sat Apr 19, 2008 4:35 am    Post subject: Re: Preload images Reply with quote

rangana wrote:
Call that function during onload Wink


Thats all it needed..
TY
Back to top
View user's profile Send private message
rangana
500+ Club


Joined: 27 Feb 2008
Posts: 629
Location: Cebu City Philippines

PostPosted: Sat Apr 19, 2008 4:52 am    Post subject: Re: Preload images Reply with quote

Yes....if you want it to work during onload...or you could always trigger the function depending on what you want,,,,either through mouseover, focus,blur...click...and a lot more...

...For the onload, you can also do it solely in the JS:
Code:

window.onload = function()
{
myimg1 = new Image(32,32);
myimg2 = new Image(32,32);
myimg1.src = “32x32.ico”;
myimg2.src = “checkbox.png”;
}
Back to top
View user's profile Send private message Yahoo Messenger
Display posts from previous:   
Post new topic   Reply to topic    DEVPPL Forum Index -> JavaScript Forum All times are GMT + 1 Hour
Page 1 of 1

 
 
Welcome to DEVPPL.com
You are not logged in, which means that you can't post in the forums.
Click here to Register

If you are a current member here on DEVPPL, please login below:

User: Pass:
Log me on automatically each visit:

 


Powered by phpBB © 2001, 2005 phpBB Group - Modified by DEVPPL

Flash Games - Sitemap