<HTML>
<Head>
<Title> window animation </title>
<SCRIPT type = "text/JavaScript">
VaR bounce = {
X: 0, Y: 0, W: 200, H: 200, // window position and size;
DX: 5, DY: 5, // window velocity (speed) _ moving distance;
Interval: 100, // The interval is 100 milliseconds;
Win: NULL, // storage creation window;
Timer: NULL, // return value of setinterval ();
// Start the animation;
Start: function (){
// Start with the window in the center of the screen;
Bounce. x = (screen. width-bounce.w)/2;
Bounce. Y = (screen. height-bounce.h)/2;
Bounce. Win = Window. Open ('javascript: "Bounce. Timer = setinterval (bounce. nextframe, bounce. interval );
},
// Stop the animation;
Stop: function (){
Clearinterval (bounce. Timer );
If (! Bounce. Win. Closed ){
Bounce. Win. Close ();
}
},
// Display the next frame of the animation.
Nextframe: function (){
// If the user closed the window, stop the animation;
If (bounce. Win. Closed ){
Clearinterval (bounce. Timer );
Return;
}
// Bounce if we have reached the right or left edge (edge );
If (bounce. x + bounce. dx> (screen. availWidth-bounce.w) | (bounce. x + bounce. DX <0 )){
Bounce. dx =-bounce. dx;
}
// Bounce if we have reached the bottom or top edge;
If (bounce. Y + bounce. Dy> (screen. availHeight-bounce.h) | (bounce. Y + bounce. Dy <0 )){
Bounce. DY =-bounce. Dy;
}
// Update the current position of the window;
Bounce. x + = bounce. dx;
Bounce. Y + = bounce. Dy;
// Finally, move the window to the new position;
Bounce. Win. moveTo (bounce. X, bounce. y );
// Display current position in window status line;
Bounce. Win. defaultstatus = "(" + bounce. x + "," + bounce. Y + ")";
}
};
</SCRIPT>
</Head>
<Body>
<Button onclick = "bounce. Start ()"> start to move the window </button>
<Button onclick = "bounce. Stop ()"> stop moving window </button>
</Body>
</Html>