...

View Full Version : Image Swap SEMI working -- Any Suggestions?



KimHuff
10-27-2003, 08:26 AM
It looks like I found the script I needed, but it seems to "semi" work properly. What I am looking for is a script that will swap out an image when you click on it. Although it works, I cannot get it to swap on the first click. It will swap with a second click. I thought maybe it was because the image had not loaded so I gave it plenty of time but it still required two clicks.

Here is a link of the example I grabbed from the forum. You will notice that it does swap on the first click.

http://65.18.217.19/test.html

Here is a sample using my images, unfortunately it takes two clicks. And even double clicking did not work.

http://65.18.217.19/index2.htm

Here it is as I am using it on the website. The reason I thought I should show you this one too is I am using more than one function for this image at the same time. I dont feel this is the problem because even using it in the example above without the additional functions, it still requires two clicks.

http://65.18.217.19/about.php

Finally, I am unable to get the mouse arrow to switch to a hand showing the visitors that this is a link.

Your suggestions are greatly appreciated. Thank you in advance.

Kim

PS. I thought I better mention that I am using Windows XP Home with the most recent IE updates.

glenngv
10-27-2003, 09:32 AM
it is because you swaps the same image. On first click, the latched variable is undefined so this.src=$.src.

Try this:
onclick="this.src=(this.latched)?$.src:$$.src;this.latched=!this.latched"

I made it as $$.src not $$ only because you also need to preload the 2nd image.

<script type="text/javascript">
var $ = new Image();
$.src = 'http://65.18.217.19/images/mel_gibson4.jpg';
var $$ = new Image();
$$.src = 'http://65.18.217.19/images/drz.jpg';
</script>

KimHuff
10-27-2003, 11:02 AM
Glenn,

Thanks for the changes you made. I am not sure if I understand why the example from wsabstract worked and mine didnt since all I did was change the images, but the changes you made worked beautifully. :D

Thank you for your time,

Kim



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum