//oDrag为容器最大宽高的标准。
//handle为点击拖拉移动的地方。
function drag(oDrag, handle){
handle.onmousedown = function(event){
var event = event||window.event;
var maxW = document.documentElement.clientWidth - oDrag.offsetWidth;
var maxH = document.documentElement.clientHeight - oDrag.offsetHeight;
var disX = event.clientX - oDrag.offsetLeft;
var disY = event.clientY - oDrag.offsetTop;
document.onmousemove = function(event){
var event = event || window.event;
var myX = event.clientX - disX;
var myY = event.clientY - disY;
myX = myX < 0 ? 0 : myX;
myX = myX > maxW ? maxW : myX;
myY = myY > maxH ? maxH : myY;
myY = myY < 0 ? 0 : myY;
oDrag.style.left = myX + ‘px‘;
oDrag.style.top = myY + ‘px‘;
return false;
}
document.onmouseup = function(){
document.onmousemove = null;
this.releaseCapture && this.releaseCapture() }
}
this.setCapture && this.setCapture();
return false}