Javascriptは簡単にドラッグできるdivを実現します.

1087 ワード

 
  


<br>var x; <br>var y; <br>function $(id) <br>{ <br>return document.getElementById(id) <br>} <br>function mousedown() <br>{ <br>x=event.clientX-$("px").style.pixelLeft; <br>y=event.clientY-$("px").style.pixelTop; <br>$("px").style.border="2px solid red"; <br>$("px").onmousemove = mousemove; <br>} <br>function mouseup() <br>{ <br>$("px").onmousemove = ""; <br>$("px").style.border=""; <br>} <br>function mousemove() <br>{ <br>$("px").style.pixelLeft=event.clientX-x; <br>$("px").style.pixelTop=event.clientY-y; <br>} <br>


onmousedown="mousedown()" onmouseup="mouseup()" >