Results 1 to 4 of 4

Thread: How do i do animation in Javascript?

  1. #1

    Thread Starter
    Addicted Member ddmeightball's Avatar
    Join Date
    Nov 2004
    Location
    Nebraska
    Posts
    183

    How do i do animation in Javascript?

    I have never done animation in javascript and want to know how. What I want to learn how to do is basically take a ball image and make it go around the four corners of the broswer window. Anybody know how?

  2. #2
    Frenzied Member ober0330's Avatar
    Join Date
    Dec 2001
    Location
    OH, USA
    Posts
    1,945

    Re: How do i do animation in Javascript?

    http://www.google.com/search?q=javas...utf-8&oe=utf-8

    Google does. Come back here when you run into errors with the code.
    format your code!! - [vbcode] [/vbcode]

    ANSWERS CAN BE FOUND HERE!!

    my personal company

  3. #3

    Thread Starter
    Addicted Member ddmeightball's Avatar
    Join Date
    Nov 2004
    Location
    Nebraska
    Posts
    183

    Re: How do i do animation in Javascript?

    Ok, here is my code. I can get the ball to move back and forth but how do I get it to go up and down? Here is what I mean...What i want as the end result is for it to go all the way around the screen, and, until the user clicks the stop action button, it will just keep going.

    I know i can change from left and right:
    Code:
    document.all.BallID.style.left = currentPos + moving;
    top up and down
    Code:
    document.all.BallID.style.top = currentPos + moving;
    but how to get it to go around and round and round?(follow the arrows)
    --<-
    :-- :
    :-- :
    v--^
    :-- :
    :-- :
    -->-




    Code:
    <html>
    
    <head>
    <title>My animation</title>
    
    <SCRIPT LANGUAGE = "JavaScript1.2">
    
    <!--
    var moving=0;
    var movingamount =10
    function moveBall(currentPos){
    
    	moving += movingamount;		
    	document.all.BallID.style.left = currentPos + moving;
    			if(moving > 670)
    			{ 
    				movingamount = -10;
    				
    			}
    			if(moving < 0)
    			{
    				movingamount = 10;
    			}
    }
    -->
    </script>
    </head>
    
    <body topmargin=0 leftmargin="0">
    
    
    		 <SPAN ID=BallID STYLE="position:absolute; left=50; top=50"><img name = "8Ball" src="eightball.gif"></SPAN>
    		<form name=sample2>
    			<input type="button" value="   Move Eightball   " name="move"  onClick="movement=setInterval('moveBall(40)', 50);">
    			<input type="button" value="   Stop action   " name="move"  onClick="clearInterval(movement);">
            </form>
    
    </body>
    
    </html>
    Last edited by ddmeightball; Dec 9th, 2004 at 09:34 PM.

  4. #4

    Thread Starter
    Addicted Member ddmeightball's Avatar
    Join Date
    Nov 2004
    Location
    Nebraska
    Posts
    183

    Re: How do i do animation in Javascript?

    Can anyone help me with this?

Posting Permissions

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



Click Here to Expand Forum to Full Width