拖拽
var box = document.getElementById('d_box');
var drop = document.getElementById('drop');
var box_close = document.getElementById('box_close');
drop.onmousedown = function(e) {
e = e || event;
var x = e.clientX - box.offsetLeft;
var y = e.clientY - box.offsetTop;
document.onmousemove = function(e) {
var boxLeft = e.clientX - x;
var boxTop = e.clientY - y;
if(boxLeft < 0) {
boxLeft = 0;
} else if(boxLeft > (document.documentElement.clientWidth - box.offsetWidth)){
boxLeft = document.documentElement.clientWidth - box.offsetWidth;
}
if(boxTop < 0) {
boxTop = 0;
} else if(boxTop > (document.documentElement.clientHeight - box.offsetHeight)){
boxTop = document.documentElement.clientHeight - box.offsetHeight;
}
box.style.left = boxLeft + "px";
box.style.top = boxTop + "px";
}
document.onmouseup = function (e){
document.onmousemove = null;
}
}
box_close.onclick = function(){
this.parentNode.parentNode.style.display = "none";
}