...

View Full Version : Can onclick image swap change different image?



matto
12-11-2007, 10:45 PM
Hi, I'm very new to java; about the only thing I know how to do successfully are onmouseover events. I've been searching for an hour on many different sites and I haven't found the answer to my question.

I'm creating an image gallery and I am currently using an iframe and the target command to have the full-size images appear on the page without having to reload it. I would like to, instead, start off with a blank image and, when the user clicks on an icon, have that blank image swap to the full-size version of the icon. Is this possible?

To reiterate, is it possible to click on icon1.jpg and cause that to swap pictureA.jpg with pictureB.jpg?

Any help would be greatly appreciated.

Majoracle
12-11-2007, 11:31 PM
http://www.huddletogether.com/projects/lightbox2/

That might be a nice thing for you to try. It's easy and free, and works great. I see a lot of sites that use it.

matto
12-11-2007, 11:37 PM
Wow, that's... pretty amazing. Thanks a lot! :)

Actinia
12-12-2007, 04:53 PM
You first need to preload the images that are swapped in/out:

var im1 = new Image(); im1.src = "image1.jpg";
var im2 = new Image(); im2.src = "image2.jpg";
Then you need to identify the target image:

<img id="target" src="blank.jpg" />
Now your clickable image should have a onclick event attached:

<a href="#" onclick="target.src=im1.src; return false;"><img src="icon1.jpg" /></a>

<a href="#" onclick="target.src=im2.src; return false;"><img src="icon2.jpg" /></a>

John Rostron

shakir
12-12-2007, 05:40 PM
its possible with javascript.. very simple just check in jscript tutorial. You can get bult in script also for all this. m also doing like this for one of my site

matto
12-12-2007, 08:52 PM
thanks for all the advice, it's working great!



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum