Control the movement of small squares with keyboard elements _ javascript skills

Source: Internet
Author: User
Control the movement of small squares with keyboard Elements

<HTML> <HEAD> <! -- Code by hongseheike <TITLE> Control of keyboard elements </TITLE> <SCRIPT language = javascript> ns4 = (document. layers )? True: false; ie4 = (document. all )? True: false; function init () {if (ns4) {block = document. blockDiv;} if (ie4) {block = blockDiv. style;} block. xpos = parseInt (block. left); block. active = false; document. onkeydown = keyDown; document. onkeyup = keyUp; if (ns4) {document. captureEvents (Event. KEYDOWN | Event. KEYUP) ;}} function keyDown (e) {if (ns4) {var nkey = e. which; var iekey = 0;} if (ie4) {var iekey = event. keyCode; var nkey = 0;} if (nkey = 97 | iekey = 65 )&&! Block. active) {block. active = true; slide () ;}} function keyUp (e) {if (ns4) {var nkey = e. which; var iekey = 0;} if (ie4) {var iekey = event. keyCode; var nkey = 0;} if (nkey = 97 | iekey = 65) {block. active = false ;}} function slide () {if (block. active) {block. xpos + = 5; block. left = block. xpos; status = block. xpos; setTimeout ("slide ()", 30) ;}} SCRIPT </pead> <BODY onLoad = "init ()"> // Javascript Document <cente R> press the "A" key to slide the square </center> ~ V ~ </BODY> </HTML>
[Ctrl + A select all Note: If you need to introduce external Js, You need to refresh it to execute]

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.