javascriptマウスでアイコンをドラッグする技術

960 ワード

この例は簡単に言えば、マウスでアイコンをドラッグして行きたいところに行きます.
コード


<br>var bb = document.getElementById("block"); <br>bb.onmousedown = function(){ <br>// <br>var pageX = event.clientX; <br>var pageY = event.clientY; <br>// block , <br>var offX = parseInt(this.style.left)||0; <br>var offY = parseInt(this.style.top)||0; <br>// block <br>var offLX = pageX-offX; <br>var offLY = pageY-offY; <br>if(!document.onmousemove){ <br>document.onmousemove = function(){ <br>bb.style.left=event.clientX-offLX; // block X <br>bb.style.top=event.clientY-offLY; // block Y <br>} <br>} <br>} <br>document.onmouseup = function(){document.onmousemove = null;} // <br>