http://www.blueidea.com/tech/web/2006/3791_5.asp
document.onmousemove = mouseMove;
document.onmouseup = mouseUp;
var dragObject = null;
var mouseOffset = null;
function getMouseOffset(target, ev){
ev = ev || window.event;
var docPos = getPosition(target);
var mousePos = mouseCoords(ev);
return {x:mousePos.x - docPos.x, y:mousePos.y - docPos.y};
}
function getPosition(e){
var left = 0;
var top = 0;
while (e.offsetParent){
left += e.offsetLeft;
top += e.offsetTop;
e = e.offsetParent;
}
left += e.offsetLeft;
top += e.offsetTop;
//return {
// x:ev.clientX + document.body.scrollLeft - document.body.clientLeft,
// y:ev.clientY + document.body.scrollTop - document.body.clientTop
// };
return {x:left, y:top};
}
function mouseMove(ev){
ev = ev || window.event;
var mousePos = mouseCoords(ev);
if(dragObject){
dragObject.style.position = 'absolute';
dragObject.style.top = mousePos.y - mouseOffset.y;
dragObject.style.left = mousePos.x - mouseOffset.x;
return false;
}
}
function mouseUp(){
dragObject = null;
}
function makeDraggable(item){
if(!item) return;
item.onmousedown = function(ev){
dragObject = this;
mouseOffset = getMouseOffset(this, ev);
return false;
}
}
var targWidth = parseInt(curTarget.offsetWidth);
var targHeight = parseInt(curTarget.offsetHeight);
setAttribute('startWidth', parseInt(offsetWidth));
setAttribute('startHeight', parseInt(offsetHeight));
setAttribute('startLeft', pos.x);
setAttribute('startTop', pos.y);
(getAttribute('startTop')
<script language="javascript">
var currentObj=null;
var offleft;
var offtop;
function funMup()
{
currentObj=null;
}
function funMdown(obj)
{
currentObj=obj;
offleft=event.x-obj.style.pixelLeft;
offtop=event.y-obj.style.pixelTop;
}
document.onmouseup=funMup;
function funMove()
{
if(currentObj!=null)
{
//alert()
currentObj.style.top=event.y-offtop;
currentObj.style.left=event.x-offleft;
//currentObj.style.pixelTop=event.y-offtop;
//currentObj.style.pixelLeft=event.x-offleft;
}
}
document.onmousemove=funMove;
function dd()
{
if(currentObj!=null)
{
//alert()
currentObj.style.top=event.y-offtop;
currentObj.style.left=event.x-offleft;
//currentObj.style.pixelTop=event.y-offtop;
//currentObj.style.pixelLeft=event.x-offleft;
}
}
function funclick()
{
var bb=testfun();
alert(bb.x);
}
function testfun()
{
return{x:00,y:11};
}
function cl()
{
alert( document.body.clientTop);
alert(event.clientX);
alert(event.srcElement.id);
}
function ma()
{
alert(arguments.length);
}
</script>