Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3
  1. #1
    New Coder
    Join Date
    Jul 2002
    Location
    Indianapolis, Indiana
    Posts
    24
    Thanks
    0
    Thanked 0 Times in 0 Posts

    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.

  • #2
    Supreme Master coder! glenngv's Avatar
    Join Date
    Jun 2002
    Location
    Philippines
    Posts
    11,042
    Thanks
    0
    Thanked 251 Times in 247 Posts
    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>

  • #3
    New Coder
    Join Date
    Jul 2002
    Location
    Indianapolis, Indiana
    Posts
    24
    Thanks
    0
    Thanked 0 Times in 0 Posts

    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


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •