SitePoint Sponsor

User Tag List

Results 1 to 3 of 3
  1. #1
    SitePoint Member
    Join Date
    Oct 2010
    Posts
    20
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Make the leaves fall

    I worked on this last year and could not get it working so I thought I would try to get it to work again. It looks correct to me but I must be missing something. All help greatly appreciated.
    Code:
     <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
                 "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> 
     
                  <html xmlns="http://www.w3.org/1999/xhtml"> 
                  <head>
                    <title></title>
                   <meta http-equiv="content-type" content="text/html; charset=iso-8859-1" />
                   <script type="text/javascript">
                     /* <![CDATA[ */
                     
                      var leaf = New Array(6);
                      var curLeaf = 0;
                       var begin;
    		           var imagesLoaded = 0;
    		           
                      for (var imagesLoaded=0; imagesLoaded < 6; ++imagesLoaded) {
    	                   leaf[imagesLoaded] = new Image();
    	                   leaf[imagesLoaded].src = "leaf" + imagesLoaded + ".gif";
    	                   if (imagesLoaded == 15)
    	                       setInterval("fall()", 200);
    	             }
                      function fall() {
    	                  if (curLeaf == 5)
    	                          curLeaf = 0;
    	                  else 
    	                       ++curLeaf;
    	                  document.getElementById("leafImage").src= leaf[curleaf].src;
    	                  
    	            }
                      
                     /* ]]> */
                     </script>
                     </head>
    
         
                     <body>
                          <img src="leaf0.gif" id="leafImage" height="100" width="200" alt="Image of a leaf." />
              
                          
             
                     </body>
                     </html>

  2. #2
    Non-Member Kalon's Avatar
    Join Date
    Aug 2010
    Location
    At my computer
    Posts
    2,012
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    1) you have at least 1 syntax error.

    2) you are calling fall(), which references the element "leafImage" before the element is loaded.

    3) if you still have problems after fixing 1) and 2) you can place alert('got here') statements in your code, along with alert()'s to display variable values to find logic errors in your code.

  3. #3
    SitePoint Member
    Join Date
    Oct 2010
    Posts
    20
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by Kalon View Post
    1) you have at least 1 syntax error.

    2) you are calling fall(), which references the element "leafImage" before the element is loaded.

    3) if you still have problems after fixing 1) and 2) you can place alert('got here') statements in your code, along with alert()'s to display variable values to find logic errors in your code.
    I found the mistakes and corrected them and it works great now thank you for the help.


Tags for this Thread

Bookmarks

Posting Permissions

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