先复制一下,看看运行的效果吧,其中用到的精髓是setInterval()方法: 复制代码 代码如下: JavaScript <BR>html<BR>{<BR>background-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>a b