简单的拖动代码
<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);" >
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);" >
浙公网安备 33010602011771号