1. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Oct 2000
    Rep Power

    Javascript Image Caching Problem


    I am trying to use Javascript to enable me to do some image swapping.

    I found a script in the O'Reilly book but try as I may I cannot get the thing to work.

    I have a feeling it is something to do with the images not caching.

    It is really doing my head in!

    Can someone please have a look and tell me where I am going wrong?

    Many thanks


    Heres the code -

    <title>Untitled Document</title>
    <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />


    <img src="image1.jpg" name="animation">

    <script language="JavaScript">
    var images = new Array(10);
    for(var i = 1; i < 10; i++) {
    images[i] = new Image();
    images[i].src = "image" + i + ".jpg";

    function animate()
    document.animation.src = images[frame].src;
    frame = (frame + 1)%10;
    timeout_id = setTimeout("animate()", 250);

    var frame = 0;
    var timeout_id = null;

    <input type=button value="Start" onClick="if (timeout_id==null) animate()">
    <input type=button value="Stop" onClick="if (timeout_id) clearTimeout(timeout_id); timeout_id=null;">

  2. #2
  3. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Apr 2003
    Rep Power
    I cant help you with the code right know, but if you are only trying to swap a IMG i suggest you use programs like DreamWeaver or Adobe Image Ready

IMN logo majestic logo threadwatch logo seochat tools logo