最初にコピーして、実行中の効果を確認します。使用される本質は setInterval() メソッドです。 コードをコピーしますコードは次のとおりです: JavaScript<br>html<br>{<br>背景- color:silver;<br>}<br>.point1<br>{<br>position:absolute;<br>left:10px;<br>top:40px; <p>}<br>.point2<br>{<br>position:absolute;<br>left:100px;<br>top:40px;<br>}<br>.hr1<br>{<br> Position:absolute;<br>top:60px;<br>}<br><br>document.onmousedown = Mousedown;<br> document.onmouseup = Mouseup;<br>var intervalProcess;<br>var direct = true;<br>function Mousedown(){<br>intervalProcess = setInterval("MovePoint()", 1);<br>}<br>function Mouseup(){<br>clearInterval(intervalProcess);<br>}<br>function MovePoint(){<br>with (document.getElementById("point1").style){<br>if (isNaN( parseInt(left)))<br>left = "10px";<br>else {<br>document.getElementById("point2").style.left = "200px";<br>if (parseInt(left) < ; 0)<br>direct = true;<br>if (parseInt(left) > parseInt(document.getElementById("point2").style.left))<br>direct = false;<br>if (direct )<br>left = parseInt(left) 1 "px";<br>else<br>left = parseInt(left) - 1 "px";<br>}<br>}<br>}<br>< ;/script><br></head><br><body><br><div class="point1" id="point1"><font color=blue>a</font>< ;/div><br><div class="point2" id="point2"><font color=red>b</font></div><br><hr class="hr1" /><br></body><br></html><br></p> </div>