<meta cahrset="utf-8" & gt;
<style type="text/CSS" & gt;
* {
Margin: 0 px;
Padding: 0 px;
}
# BTN {
Position: absolute;
Top: 200 px;
Left: 20 px;
}
# smallBall {
Width: 100 px;
Height: 100 px;
The line - height: 100 px;
The text - align: center;
/* border: 1 px solid black */
Border - the radius: 100%;
Background - color: # ff0000;
Position: absolute;
Top: 50 px;
Left: 0 px;
}
</style>
<body>
Var smallBall=document. GetElementById (" smallBall ");
Var speed=10;
Var x=true;
BTN. Onclick=function () {
Var time=setInterval (run, 30);
The function the run () {
If (smallBall. OffsetLeft=="0") {
X=true;
} else if (smallBall. OffsetLeft=="600") {
X=false;
}
If (x==true) {
SmallBall. Style. Left=smallBall. OffsetLeft + speed + "px";
} else {
SmallBall. Style. Left=smallBall. OffsetLeft -speed + "px";
}
}
}
</script>