Debt Consolidation - Turquoise Jewelry - Free Music Download - Cheat Codes - Wordpress Themes

PDA

View Full Version : Toggling images


frenz
Feb 13th 2007, 4:51 am
Hi,

I'm facing a simple problem and would be great if someone could help me out. I have two images play.jpg and pause.jpg. I also have an <img>, in its onclick im calling a javascript function which will toggle between these images each time the image is clicked. The size of the image is 842 bytes which is the maximum I can compress. The problem is that each time I click the image, the image is downloaded from the server and only then it gets displayed, which means it would take around 2-3 seconds for the image to get displayed. I have also tried putting the image in cache this way:

var Play = new Image();

But this also has done no good. By the way, once the image is being downloaded from the server, why does it download it each time I click the image? Is there any solution to this.


Thanks & Regards,
Frenz

nico_swd
Feb 13th 2007, 5:53 am
You're not preloading it correctly. Try this.



var Play = new Image();
Play.setAttribute('src', '/path/to/play.jpg');