JS 简单拖动代码

<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);" >

你可能感兴趣的:(js)