Exercise-The villain moves

Source: Internet
Author: User

<! DOCTYPE html>;} #wrap {width:500px;height:500px;border:1px solid green;margin:10px auto; position:relative;} #wrap Img{position:absolute;top:0;left:0;}</style>//get the object of the villain        varren = document.getElementById (' ren ')); //bind keyboard-pressed eventsDocument.onkeydown =function(event) {//dealing with compatibility issues            varE = Window.event | |event; //set the stride length for each move of a person            varStep = 10; /*w-87 s-83 a-65 d-68*/            Switch(e.keycode) { Case87://onRen.style.top = Math.max (0,ren.offsettop-step) + ' px '; //Ren.style.top = ren.offsettop-step+ ' px ';Changeimg (' u1.gif ', ' u2.gif ');  Break;  Case83://under                    //alert (ren.offsettop); Current top Value                    //Ren.style.top = ren.offsettop+step+ ' px ';                    //down Border Top 470 If the 470 is large take 470Ren.style.top = Math.min (470,ren.offsettop+step) + ' px '; Changeimg (' B1.gif ', ' b2.gif ');  Break;  Case65://left                    //Ren.style.left = ren.offsetleft-step+ ' px ';Ren.style.left = Math.max (0,ren.offsetleft-step) + ' px '; Changeimg (' L1.gif ', ' l2.gif ');  Break;  Case68://Right                    //Ren.style.left = ren.offsetleft+step+ ' px ';Ren.style.left = Math.min (470,ren.offsetleft+step) + ' px '; Changeimg (' R1.gif ', ' r2.gif ');  Break;  Case81: Alert (' You have gone ' +i+ ' step ~); }        }        ////Change chart method        //function changeimg (img1,img2) {        ////Truncate file name from absolute path        //var newtu = Ren.src.substr (Ren.src.lastIndexOf ('/') +1);        ////To determine the displayed picture according to the direction        //if (newtu = = img1) {        //ren.src = ' images/' +img2;        //}else{        //ren.src = ' images/' +img1;        //     }        // }        vari = 0; functionchangeimg (IMG1, img2) {if(i%2==0) {//Maybe it's right to just write i%2.REN.SRC = ' images/' +Img2; }Else{ren.src= ' images/' +IMG1; } I++; }    </script>

Online Address: http://yupinghua.com/practices/components/%E5%B0%8F%E4%BA%BA%E7%A7%BB%E5%8A%A8.html

Exercise-The villain moves

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.