lz可以参考下面的代码:
var div;
var backdiv;
var movediv;
var oldx;
var oldy;
var olddiv;
var adddiv;
document.onmousemove = move;
function createDiv(name) {
div = document.getElementById(name);
if (div) {
return;
}
var bodyHeight = document.body.scrollHeight < document.body.clientHeight ? document.body.clientHeight : document.body.scrollHeight;
var bodyWidth = document.body.scrollWidth < document.body.clientWidth ? document.body.clientWidth : document.body.scrollWidth;
createBackDiv(bodyHeight, bodyWidth);
div = document.createElement("div");
div.id = name;
div.style.position = "absolute";
div.style.backgroundColor = "#DCDCDC";
div.style.width = 440;
div.style.height = 350;
div.style.top = bodyHeight / 2 - 230;
div.style.left = bodyWidth / 2 - 300;
return div;
}
function createBackDiv(bodyHeight, bodyWidth) {
backdiv = document.createElement("div");
backdiv.style.position = "absolute";
backdiv.style.left = 1 + "px";
backdiv.style.top = 1 + "px";
backdiv.style.height = bodyHeight;
backdiv.style.width = bodyWidth;
backdiv.style.background = "#F0FFFF";
backdiv.index = "10";
backdiv.style.filter = "alpha(Opacity=20)";
document.body.appendChild(backdiv);
}
function updatecordown() {
movediv = document.getElementById("cor");
oldx = event.x - movediv.style.pixelLeft;
oldy = event.y - movediv.style.pixelTop;
movediv.style.cursor = "hand";
}
function updateinddown() {
movediv = document.getElementById("ind");
oldx = event.x - movediv.style.pixelLeft;
oldy = event.y - movediv.style.pixelTop;
movediv.style.cursor = "hand";
}
function addcordown() {
movediv = document.getElementById("addcor");
oldx = event.x - movediv.style.pixelLeft;
oldy = event.y - movediv.style.pixelTop;
movediv.style.cursor = "hand";
}
function addinddown() {
movediv = document.getElementById("addind");
oldx = event.x - movediv.style.pixelLeft;
oldy = event.y - movediv.style.pixelTop;
movediv.style.cursor = "hand";
}
function move() {
if (movediv) {
movediv.style.left = event.x - oldx;
movediv.style.top = event.y - oldy;
}
}
function up() {
if (movediv) {
movediv.style.cursor = "default";
movediv = null;
}
}