Ball movement becomes automatic keyboard control

























Clear timer, to prevent the emergence of multiple clicks a plurality of timers, ball moving speed increases successively
the clearInterval (A);
the clearInterval (B);
the clearInterval (C);
the clearInterval (D);

Several establishment timer, whenever a large frame is moved to clear the timer, establishing another timer, for a running direction
A = the setInterval (function () {
IF (oball.offsetLeft> 370) {
oball.offsetLeft = 370;
the clearInterval (A);
B = the setInterval (function () {
IF (oball.offsetTop> 370) {
oball.offsetTop = 370;
the clearInterval (B);
C = the setInterval (function () {
IF (oball.offsetLeft <0) {
= 0 oball.offsetLeft;
the clearInterval (C);
D = the setInterval (function () {
IF (oball.offsetTop <0) {
oball.offsetTop = 0
} {the else
oball.style.top + =. 5-oball.offsetTop "PX "
}

}, 30)
} the else {
oball.style.left + =. 5-oball.offsetLeft" PX "
}

}, 30)
} the else {
oball.offsetTop. 5 + + = oball.style.top "PX"
}

}, 30)
} the else {
oball.style.left. 5 + + = oball.offsetLeft "PX"
}

}, 30)
}

to clear all the keyboard is pressed timer, the keyboard to control the
document.onkeydown = function (Eve) {
the clearInterval (A);
the clearInterval (B);
the clearInterval (C);
the clearInterval (D);
E = || the window.event Eve;
IF (e.keyCode 37 [==) {
IF (oball.offsetLeft <0) {
oball.offsetLeft = 0
} {the else
oball.style.left + =. 5-oball.offsetLeft "PX";
}

}
IF (== 38 is e.keyCode) {
IF (oball.offsetTop <0) {
oball.offsetTop = 0
} {the else
oball.style.top + =. 5-oball.offsetTop "PX";
}

}
if(e.keyCode==39){
if(oball.offsetLeft>370){
oball.offsetLeft=370
}else{
oball.style.left=oball.offsetLeft+5+"px";
}

}
if(e.keyCode==40){
if(oball.offsetTop>370){
oball.offsetTop=370
}else{
oball.style.top=oball.offsetTop+5+"px";
}

}
}


</script>
</html>

Guess you like

Origin www.cnblogs.com/huangping199541/p/11432407.html