简单的拖动代码

<script>
var xx=0,yy=0;
function a(v)
{
xx=event.x-v.offsetLeft;  //取得对象减左边框的距离
yy=event.y-v.offsetTop;  //取得对象减顶边框的距离
}
function b(v)
{
v.style.left=event.x-xx;  //取得对象离左边框的距离
v.style.top=event.y-yy;  //取得对象离顶边框的距离
}
</script>
<img id="img" src="http://bbs.51js.com/images/default/logo.gif" style="position:absolute;" ondragstart="a(this);" ondrag="b(this);" >
posted @ 2006-08-18 12:48  MSDI  阅读(152)  评论(0)    收藏  举报