Why Do My Images Keep Swapping??

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Prisoner at War

    Why Do My Images Keep Swapping??


    Hi, Everybody,

    The fucntion below is called by an onLoad <imgattribute , and it is
    supposed to replace the original image, after three seconds, with
    another image. This second image shouldl be replaced, after eight
    more seconds, with the original image.

    For some reason, JavaScript keeps swapping the images back and forth
    endlessly -- and not even properly counting out all the seconds
    specified, after the first time swapping! What's going on???


    function mytest() {

    setTimeout("win dow.document.te st.src='../images/substitute.jpg' ;",
    3000);
    setTimeout("win dow.document.te st.src='../images/original.jpg';" ,
    8000);
    }
  • Bjoern Hoehrmann

    #2
    Re: Why Do My Images Keep Swapping??

    * Prisoner at War wrote in comp.lang.javas cript:
    >The fucntion below is called by an onLoad <imgattribute , and it is
    >supposed to replace the original image, after three seconds, with
    >another image. This second image shouldl be replaced, after eight
    >more seconds, with the original image.
    >
    >For some reason, JavaScript keeps swapping the images back and forth
    >endlessly -- and not even properly counting out all the seconds
    >specified, after the first time swapping! What's going on???
    >
    >function mytest() {
    > setTimeout("win dow.document.te st.src='../images/substitute.jpg' ;", 3000);
    > setTimeout("win dow.document.te st.src='../images/original.jpg';" , 8000);
    >}
    Loading each replacement image successfully also counts as "load" and so
    the code in the onload attribute is evaluated again and again. There are
    several ways to break a cycle like this, one is to simply store in a va-
    riable whether this is the first swap, and if not, skip the setTimeout.
    --
    Björn Höhrmann · mailto:bjoern@h oehrmann.de · http://bjoern.hoehrmann.de
    Weinh. Str. 22 · Telefon: +49(0)621/4309674 · http://www.bjoernsworld.de
    68309 Mannheim · PGP Pub. KeyID: 0xA4357E78 · http://www.websitedev.de/

    Comment

    Working...