*{margin:0;padding:0;}
#div1{width:100px;height:100px;background:red;position:relative;}
window.οnlοad=function(){
var div=document.getElementByIdx_x("div1"); //获得被移动元素的id
var disX=0,X=0;disY=0;
div.onmousedown = function(ev){
var oEvent= ev || window.event;
disX=oEvent.clientX; //鼠标点击位置的横坐标
disY=oEvent.clientY; //鼠标点击位置的纵坐标
disLeft=div.offsetLeft; //div块的左边距
disTop=div.offsetTop; //div块的上边距
document.onmousemove = function(ev){
var oEvent= ev || window.event;
X=oEvent.clientX-disX;
Y=oEvent.clientY-disY;
div.style.left =disLeft+X+"px";
div.style.top =disTop+Y+"px";
}
div.οnmοuseup=function(){
div.οnmοuseup=null;
document.οnmοusemοve=null;
return false;
}
}
}
#div1{width:100px;height:100px;background:red;position:relative;}
window.οnlοad=function(){
var div=document.getElementByIdx_x("div1"); //获得被移动元素的id
var disX=0,X=0;disY=0;
div.onmousedown = function(ev){
var oEvent= ev || window.event;
disX=oEvent.clientX; //鼠标点击位置的横坐标
disY=oEvent.clientY; //鼠标点击位置的纵坐标
disLeft=div.offsetLeft; //div块的左边距
disTop=div.offsetTop; //div块的上边距
document.onmousemove = function(ev){
var oEvent= ev || window.event;
X=oEvent.clientX-disX;
Y=oEvent.clientY-disY;
div.style.left =disLeft+X+"px";
div.style.top =disTop+Y+"px";
}
div.οnmοuseup=function(){
div.οnmοuseup=null;
document.οnmοusemοve=null;
return false;
}
}
}