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

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.

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

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.

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.


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

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:

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

<script type="text/javascript">
var $ = new Image();
$.src = '';
var $$ = new Image();
$$.src = '';

10-27-2003, 11:02 AM

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,