Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Javascript Animation Help

Status
Not open for further replies.

26022602

Technical User
Nov 23, 2010
11
US
I am trying to make my animation going but it seems like there is something I am missing that I couldn't figure out yet... any help will be highly appreciated.

Code:
    <script type="text/JavaScript">
    // Preloaded images
    if (document.images)
    {
      demo1 = new Image();
      demo1.src = "images/home/animation/image1.jpg";
 
      demo2 = new Image();
      demo2.src = "images/home/animation/image2.jpg";
 
      demo3 = new Image();
      demo3.src = "images/home/animation/image3.jpg";
    }
    // Reusable timer
    function timeimgs(numb)
    {
      thetimer = setTimeout("imgturn('" +numb+ "')", 1000);
    }
    // Reusable image turner
    function imgturn(numb)
    {
      if (document.images)
      {
        // This will loop the image
        if (numb == "3")
        {
          document["demo"].src = eval("demo3.src");
          timeimgs('1');
        }
        else
        {
          document["demo"].src = eval("demo" + numb + ".src");
          timeimgs(numb = ++numb);
        }
      }
    }
    </script>

  <div id="mainDisplay" onload="timeimgs('2');">
  <img src="images/home/animation/image1.jpg" width="600" height="200">
  </div>
 
You refer to "document["demo"].src" but you appear to have no item named "demo", Try putting your onload event in the <body> tag (which you appear to be missing) and give the img tag a name
Code:
<body onload="timeimgs('2');">
  <div id="mainDisplay">
  <img src="image000.jpg" name="demo" width="600" height="200">
  </div>
</body>

If you want the best response to a question, please check out FAQ222-2244 first.
'If we're supposed to work in Hex, why have we only got A fingers?'
Drive a Steam Roller
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top