核心提示://dom为拖拽对象的ID//box为外边的大的DIVwindow.onload = function(box){var _top = getCookie(top);var _left = getCo...
//dom为拖拽对象的ID
//box为外边的大的DIV
window.onload = function(box){
var _top = getCookie("top");
var _left = getCookie("left");
console.log(_top);
console.log(_left);
box.style.top = _top +"px";
box.style.left = _left + "px";
}
function haul(dom,box) {
dom.onmousedown = function (e) {
e = e || window.event;
var ox = e.offsetX;
var oy = e.offsetY;
document.onmousemove = function (e) {
e = e || window.event;
var cx = e.clientX;
var cy = e.clientY;
var _left = cx - ox;
var _top = cy - oy;
if (_left < 0) {
_left = 0
}
if (_top < 0) {
_top = 0
}
if (_left + box.offsetWidth > document.documentElement.clientWidth) {
_left = document.documentElement.clientWidth - box.offsetWidth;
}
if (_top + box.offsetHeight > document.documentElement.clientHeight) {
_top = document.documentElement.clientHeight - box.offsetHeight;
}
box.style.top = _top + "px";
box.style.left = _left + "px";
saveCookie("top", _top, 3);
saveCookie("left", _left, 3);
}
}
dom.onmouseup = function () {
document.onmousemove = null;
}
}


