Javascript _ window operations

Source: Internet
Author: User

<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>

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.