473,394 Members | 1,806 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,394 software developers and data experts.

animation function not running... please help

I am trying to have a function start with a timer and then switch to another function. However, it is not working at all. Anyone know whats goin on?


[HTML]<!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>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Untitled Document</title>

<script type="text/javascript" src="animation.js">
</script>


<script type="text/javascript" language="javascript">


function startnow () {
setContents ("counter",5);

var timer1= setTimeout("setContents('counter',4)",1000);
var timer2= setTimeout("setContents('counter',3)",2000);
var timer3= setTimeout("setContents('counter',2)",3000);
var timer4= setTimeout("setContents('counter',1)",4000);
var timer5= setTimeout("setContents('counter',0)",5000);
var timer6= setTimeout("setContents('counter', 'Go!')",6000);
var timer7= setTimeout("animation()",7000);

}


function setContents(id,val) {
document.getElementById(id).innerHTML = val;
}

function animation() {

/* return the x-coordinate of the layer named layername */

function getX(layername)
{
var theLayer = getElement(layername);
if (layerobject)
return(parseInt(theLayer.left));
else
return(parseInt(theLayer.style.left));
}


/* set animation speed and step */

var step = 3;
var framespeed = 35;

/* set animation boundaries */

var maxleft = 100;
var maxright = 600;

/* move left until boundary */

function left()
{
var currentX = getX('rightcar');
if (currentX > maxleft)
{
currentX-=step;
setX('rightcar',currentX);
move=setTimeout("left()",(1000/framespeed));
}
else
clearTimeout(move);
}

/* move right until boundary */

function right()
{
var currentX = getX('leftcar');
if (currentX < maxright)
{
currentX+=step;
setX('leftcar',currentX);
move=setTimeout("right()",(1000/framespeed));
}
else
clearTimeout(move);
}
}



</script>
</head>

<body>

<div id="counter" style="border: 1px solid black; width: 100px; height: 100px; position: absolute; left: 450px; top: 10px; font-family: Arial; font-size: 25px;">
</div>

<div id="explosion" style="border: 1px solid black; width: 100px; height: 100px; position: absolute; left: 450px; top: 300px;">
boom!
</div>

<div id="leftcar" style="border: 1px solid black; width: 210px; height: 72px; position: absolute; left: 10px; top: 300px;">
<img src="blue_car.gif" width="200" height="72" /></div>

<div id="rightcar" style="border: 1px solid black; width: 210px; height: 72px; position: absolute; left: 800px; top: 300px;">
<img src="yellow_car.gif" /></div>

<div id="controls" style="border: 1px solid black; width: 50px; height: 100px; position: absolute; left: 450px; top: 500px;">
<form action="" name="form" method="get" />
<input type="button" value="start" onclick="startnow();" />

<input type="button" value="reset" />

</form>
</div>



</body>
</html>[/HTML]
Feb 20 '07 #1
2 1798
btw the animation is based on the library from:
http://javascriptref.com/examples/ch15-ed2/15-501.htm

if that helps..
Feb 20 '07 #2
acoder
16,027 Expert Mod 8TB
You cannot have functions within a function as you have declared.

What functions are you trying to run? e.g. left 300px, then right, then up, etc.

Whatever you decide, call those functions separately in animation(), e.g.
Expand|Select|Wrap|Line Numbers
  1. function animation() {
  2. left();
  3. right();
  4. }
Feb 20 '07 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

5
by: Brian Angliss | last post by:
I'm relatively new to scripting in JavaScript, so I'm not too surprised I'm having difficulty scripting up an animation effect for my personal site. What I'm trying to do is the following: When...
6
by: Reid Goldsborough | last post by:
Hi. I'm a JavaScript neophyte. I'm trying to create a JPEG animation, with one coin (tet) morphing into another. The code doesn't work. Anybody feel like taking a shot at correcting me? It's short....
1
by: Brainless | last post by:
hi... I've recently created a dhtml thing on http://www.shapers.nl/ that animates a lot of images. The thing I want to solve is the lag that occurs when a new animation is initiated. To make...
6
by: J. J. Cale | last post by:
Hi all I get different speeds from this animation in IE6 and Mozilla. Mozilla 1.7.3 runs this much faster than IE . I'm trying to get the results that Mozilla returns. IE is too slow!! Anyone...
2
by: rdemyan via AccessMonster.com | last post by:
My application has a lot of complicated SQL statements, calculations, processing that takes time. I've created a custom form to act like a messagebox. It has 10 small rectangles on it that change...
1
by: jsavagedesign | last post by:
This is a project I have been working on lately and I keep running into problems. The idea is to be able to attaching an animation to a movie clip and call it later. Or multiple animation at once. ...
2
by: keeplearning | last post by:
Hi Friends ! Please view this ANIMATION . I want to control this animation with a play and pause button . when clicked on play button , the animation should start playing . and when clicked...
4
by: =?Utf-8?B?dmluZWV0?= | last post by:
In WPF (even with considerable improvement in version 3.5), while running multiple animations in a single window, The performance of one animation suffers a lot. for example, i have two image...
4
by: Sin Jeong-hun | last post by:
Most applications, including Windows Explorer, show some sort of 'wait' dialog with animation when a lengthy operation is going on. For example, When the Windows Explorer is searching for...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.