Go Back   CodingForums.com > :: Client side development > JavaScript programming

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 10-27-2003, 07:26 AM   PM User | #1
KimHuff
New Coder

 
Join Date: Jul 2002
Location: Indianapolis, Indiana
Posts: 24
Thanks: 0
Thanked 0 Times in 0 Posts
KimHuff is an unknown quantity at this point
Image Swap SEMI working -- Any Suggestions?

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.
KimHuff is offline   Reply With Quote
Old 10-27-2003, 08:32 AM   PM User | #2
glenngv
Supreme Master coder!


 
glenngv's Avatar
 
Join Date: Jun 2002
Location: Los Angeles, CA Original Location: Philippines
Posts: 10,241
Thanks: 0
Thanked 112 Times in 111 Posts
glenngv will become famous soon enough
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>
__________________
Glenn
_____________________________________________
Play Tower of Hanoi Android app (Ad-FREE!)
Play Tower of Hanoi Android app (FREE!)
Go to Tower of Hanoi Leaderboard
Play Tower of Hanoi Facebook app
glenngv is offline   Reply With Quote
Old 10-27-2003, 10:02 AM   PM User | #3
KimHuff
New Coder

 
Join Date: Jul 2002
Location: Indianapolis, Indiana
Posts: 24
Thanks: 0
Thanked 0 Times in 0 Posts
KimHuff is an unknown quantity at this point
Thanks...

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.

Thank you for your time,

Kim
KimHuff is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 05:29 AM.


Advertisement
Log in to turn off these ads.