2005/06/07 | JS中 拖拽功能实现
类别(WEB相关) | 评论(0) | 阅读(163) | 发表于 14:26
<span style='position:absolute;width:200;height:200;background:red' onmousedown=MouseDown(this) onmousemove=MouseMove() onmouseup=MouseUp()>aa</span>
<script>
var Obj
function MouseDown(obj){
Obj=obj
Obj.setCapture()
Obj.l=event.x-Obj.style.pixelLeft
Obj.t=event.y-Obj.style.pixelTop
}
function MouseMove(){
if(Obj!=null){
    Obj.style.left = event.x-Obj.l
    Obj.style.top = event.y-Obj.t
    }
}
function MouseUp(){
if(Obj!=null){
    Obj.releaseCapture()
    Obj=null
    }
}
</script>
0

评论Comments