简单的js拖动
window.onload = function () {
var oDiv = document.getElementById("oDiv"); //oDiv必须使用CSS定位
oDiv.onmousedown = drag;
function drag(evt) {
evt = evt || window.event;
this.onmouseup = drop;
this.onmousemove = moveDiv;
this.offset = {
x: evt.offsetX,
y: evt.offsetY
};
}
function moveDiv(evt) {
evt = evt || window.event;
this.style.left = evt.clientX - this.offset.x + "px";
this.style.top = evt.clientY - this.offset.y + "px";
}
function drop(evt) {
this.onmouseup = null;
this.onmousemove = null;
}
};