自己的js功底一向不好,所以一些简单的js功能也要到网上找,今天要做一个div拖动的功能,在网上找到一段很简单的代码,很简单,贴出来
Code
<script>
var ms;
function did(obj){
ms=obj;
event.srcElement.setCapture();
x=document.all(ms).style.pixelLeft-event.x;
y=document.all(ms).style.pixelTop-event.y;
}
function document.onmousemove(){
if(ms){
document.all(ms).style.pixelLeft=x+event.x;
document.all(ms).style.pixelTop=y+event.y;
}
}
function document.onmouseup(){
if(ms){
event.srcElement.releaseCapture();
ms=0;
}
}
</script>
<div id=a1 style=position:absolute>
<div id=a2 onmousedown=did('a1')>aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa</div>
<div id=a3>bbbbbbbbbbbbbbbbbbbbbbb</div>
</div>