Copy codeThe Code is as follows:
<! DOCTYPE html PUBLIC "-// W3C // dtd xhtml 1.0 Transitional // EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<Html xmlns = "http://www.w3.org/1999/xhtml">
<Head>
<Meta http-equiv = "Content-Type" content = "text/html; charset = gb2312"/>
<Title> uniform motion demonstration </title>
<Style type = "text/css">
<! --
# Div1 {width: 1px; height: 200px; background-color: black; position: absolute; left: 100px; top: 70px; float: left}
# Div1 span {position: absolute; top:-15px}
# Div2 {width: 1px; height: 200px; background-color: midnightblue; position: absolute; left: 800px; top: 70px; float: left}
# Div2 span {position: absolute; top:-15px}
# Div3 {width: 1px; height: 200px; background-color: fuchsia; position: absolute; left: 300px; top: 70px; float: left}
# Div3 span {position: absolute; top:-15px}
# Div4 {width: 1px; height: 200px; background-color: darkmagenta; position: absolute; left: 500px; top: 70px; float: left}
# Div4 span {position: absolute; top:-15px}
# Grap {width: 200px; height: 200px; background: red; position: absolute; left: 300px; top: 74px; float: left ;}
Input {width: 100px; margin-left: 90px ;}
-->
</Style>
<Script type = "text/javascript">
Var timeId
Function startMove (target ){
Var oDiv = document. getElementById ('grap ')
ClearInterval (timeId); // it is important to prevent multiple clicks from accelerating.
Speed = oDiv. offsetLeft <target? 8:-9;
TimeId = setInterval (function (){
If (Math. abs (oDiv. offsetLeft-target) <= 6 ){
ODiv. style. left = target + 'px '; // as long as the rectangle moves closer to the target point, it is directly moved to the target point, and the speed change cannot be noticed by the naked eye.
ClearInterval (timeId); document. title = "target" + oDiv. style. left;
}
Else {
ODiv. style. left = oDiv. offsetLeft + speed + 'px ';
}
}, 30 );
}
</Script>
</Head>
<Body>
<Div id = "div1"> <span> 100px </span> </div>
<Div id = "div2"> <span> 800px </span> </div>
<Div id = "div3"> <span> 300px </span> </div>
<Div id = "div4"> <span> 500px </span> </div>
<Input type = "button" value = "move to 100px" onclick = "startMove (100)"/>
<Input type = "button" value = "move to 300px" onclick = "startMove (300)"/>
<Input type = "button" value = "move to 500px" onclick = "startMove (500)"/>
<Input type = "button" value = "move to 800px" onclick = "startMove (800)"/>
<Div id = "grap"> </div>
</Body>
</Html>