soulcode
12-02-2009, 03:18 AM
Spent past few days helping my son for his project of manipulating bouncing ball. Please help me this script work. Once user inputs the new ani value, the ball goes out. I want user to set any value ani, int and size of the ball to achieve desired animation. Seriously urgent... Thanks!
<HTML>
<HEAD>
</HEAD>
<BODY>
<IMG ID="ball" STYLE="position: absolute; left: 325; top: 200; width: 30; height: 30;" SRC="images/ball1.gif">
<SCRIPT LANGUAGE="JavaScript">
function showAlert() {
alert('ANI=' + ani + ', INT=' + int + ', SIZE=' + wxh + '');
}
</SCRIPT>
<SCRIPT LANGUAGE="JavaScript1.2">
<!--
var myBall = document.getElementById("ball");
var loc = 200;
var ani = 10;
var direction = 0;
var int = 50;
var wxh = 30;
setInterval("myFunction()", int);
function myFunction(){
if(0 == direction)
{
/* move down */
loc += ani;
if(loc >= 500)
{
/* reached lower limit, change direction */
direction = 1;
}
}
else
{
/* move up */
loc -= ani;
if(loc < 10)
{
/* reached upper limit, change direction */
direction = 0;
}
}
myBall.style.top = loc;
}
// -->
</SCRIPT>
<SCRIPT LANGUAGE="JavaScript1.2">
function readText (form) {
if(form.f_ani.value != ""){
ani = form.f_ani.value ;
myBall = document.getElementById("ball");
loc = 200;
direction = 0;
int = 50;
setInterval("myFunction()", int);
myFunction();
}
showAlert();
}
</SCRIPT>
<FORM action="" method="Get">
Ball Movement (10 pixels):<input type='text' NAME="f_ani" value="10" size="20"><br>
Interval (200 milliseconds):<INPUT type="text" id="f_int" value="200" size="20" name="1"><br>
Ball Size (10 pixels W&H):<INPUT type="text" id="f_size" value="30" size="20" name="2"><br>
<input type='button' value='Send' onclick="readText(this.form)"> <INPUT type="reset">
</FORM>
</BODY>
</HTML>
<HTML>
<HEAD>
</HEAD>
<BODY>
<IMG ID="ball" STYLE="position: absolute; left: 325; top: 200; width: 30; height: 30;" SRC="images/ball1.gif">
<SCRIPT LANGUAGE="JavaScript">
function showAlert() {
alert('ANI=' + ani + ', INT=' + int + ', SIZE=' + wxh + '');
}
</SCRIPT>
<SCRIPT LANGUAGE="JavaScript1.2">
<!--
var myBall = document.getElementById("ball");
var loc = 200;
var ani = 10;
var direction = 0;
var int = 50;
var wxh = 30;
setInterval("myFunction()", int);
function myFunction(){
if(0 == direction)
{
/* move down */
loc += ani;
if(loc >= 500)
{
/* reached lower limit, change direction */
direction = 1;
}
}
else
{
/* move up */
loc -= ani;
if(loc < 10)
{
/* reached upper limit, change direction */
direction = 0;
}
}
myBall.style.top = loc;
}
// -->
</SCRIPT>
<SCRIPT LANGUAGE="JavaScript1.2">
function readText (form) {
if(form.f_ani.value != ""){
ani = form.f_ani.value ;
myBall = document.getElementById("ball");
loc = 200;
direction = 0;
int = 50;
setInterval("myFunction()", int);
myFunction();
}
showAlert();
}
</SCRIPT>
<FORM action="" method="Get">
Ball Movement (10 pixels):<input type='text' NAME="f_ani" value="10" size="20"><br>
Interval (200 milliseconds):<INPUT type="text" id="f_int" value="200" size="20" name="1"><br>
Ball Size (10 pixels W&H):<INPUT type="text" id="f_size" value="30" size="20" name="2"><br>
<input type='button' value='Send' onclick="readText(this.form)"> <INPUT type="reset">
</FORM>
</BODY>
</HTML>