JavaScript Animation Problem (Fat cats dancing) -


i not sure why cats not moving @ all. pretty sure suppose too. can point me if suppose , or did wrong thanks.

   <!doctype html public "-//w3c//dtd xhtml 1.0 transitional//en"    "http://www.w3.org/tr/xhtml1/dtd/xhtml1-transitional.dtd">   <html xmlns="http://www.w3.org/1999/xhtml">    <head>     <title>fat cat dancing</title>   <meta http-equiv="content-type" content="text/html;charset=utf-8" />   <script type= "text/javscript">   <![cdata[   var cats = new array(3);   var fatcat = 0;    var direction;    var begin;   cats[0] = "fatcat0.gif";  cats[1] = "fatcat1.gif";  cats[2] = "fatcat2.gif"; function dance() {      if (fatcat == 0)              direction = "right";     else if (fatcat == 2)                   direction = "left"   if (direction == "right")              ++fatcat;          else if (direction == "left")                  --fatcat;              document.animation.src = cats[fatcat];      }  function startdancing() {      if (begin)              clearinterval(begin);          begin = setinterval("dance()",200);  } ]]> </script>   </head>   <body>   <h1>fat cat dancing</h1>    <p><img src="fatcat1.gif" name="animation" alt="animation" id="animation"/></p>    <form action= "">    <input type="button" name="run" value="start dancing" onclick="startdancing();"/>   <input type="button" name="stop" value="stop dancing " onclick="clearinterval(begin);"/>  </form>  </body> </html>  

try:

document.getelementbyid('animation').src = cats[fatcat]; 

your code assuming element available name property of "document", won't.

also, answer suggests, "setinterval()" call can just:

begin = setinterval(dance, 200); 

Comments

Popular posts from this blog

php - What is the difference between $_SERVER['PATH_INFO'] and $_SERVER['ORIG_PATH_INFO']? -

fortran - Function return type mismatch -

queue - mq_receive: message too long -