可以拖拽的弹出层(并实现最大化,最小化,iframe/HTML)


//拖拽对象
function drag(elementToDrag, event) {
var startX = event.clientX, startY = event.clientY;
var origX = elementToDrag.offsetLeft, origY = elementToDrag.offsetTop;
var deltaX = startX - origX, deltaY = startY - origY;
if (document.addEventListener) {
document.addEventListener("mousemove", moveHandler, true);
document.addEventListener("mouseup", upHandler, true);
}
else if (document.attachEvent) {
elementToDrag.setCapture();
elementToDrag.attachEvent("onmousemove", moveHandler);
elementToDrag.attachEvent("onmouseup", upHandler);
elementToDrag.attachEvent("onlosecapture", upHandler);
}
else {
var oldmovehandler = document.onmousemove;
var olduphandler = document.onmouseup;
document.onmousemove = moveHandler;
document.onmouseup = upHandler;
}
if (event.stopPropagation) event.stopPropagation();
else event.cancelBubble = true;
if (event.preventDefault) event.preventDefault();
else event.returnValue = false;
function moveHandler(e) {
if (!e) e = window.event;
elementToDrag.style.left = (e.clientX - deltaX) + "px";
elementToDrag.style.top = (e.clientY - deltaY) + "px";
if(e.clientX - deltaX<0)elementToDrag.style.left = "0px";//out of screen
if(e.clientY - deltaY<0)elementToDrag.style.top = "0px";//out of screen
if (e.stopPropagation) e.stopPropagation();
else e.cancelBubble = true;
}
function upHandler(e) {
if (!e) e = window.event;
if (document.removeEventListener) {
document.removeEventListener("mouseup", upHandler, true);
document.removeEventListener("mousemove", moveHandler, true);
}
else if (document.detachEvent) {
elementToDrag.detachEvent("onlosecapture", upHandler);
elementToDrag.detachEvent("onmouseup", upHandler);
elementToDrag.detachEvent("onmousemove", moveHandler);
elementToDrag.releaseCapture();
}
else {
document.onmouseup = olduphandler;
document.onmousemove = oldmovehandler;
}

if (e.stopPropagation) e.stopPropagation();
else e.cancelBubble = true;
}
}
//window 弹出层
var win = function() {
this.imageURL = "http://www.gpsoo.net/dealer/images/";
this.nullUrl = "http://www.gpsoo.net/images/";
};
win.prototype.openWinLayer = function(title, htmlStr, width, height, contentType, win, callback)
{
overWindow = win;
this.closeWinLayer();
var title = '<div id="tit" onmousedown=\'drag(document.getElementById("openWinLayerDIV"),event)\' style="height:24px;background:#2b98cd;color:#FFF;cursor:move;"><div style="float:left;width:auto;padding-left:10px;height:24px;line-height:24px;font-size:12px;font-weight:bold;">' + title + '</div><div style="float:right;padding-right:4px;padding-top:3px;"><a style="cursor:pointer;" onclick="win.minWinLayer(\'' + title + '\');"><img src="' + this.imageURL + 'iw_min.gif" border="0" /></a><a><img src="' + this.nullUrl + 'null.gif" width="5" height="14" border="0" /></a><a style="cursor:pointer;" onclick="win.closeWinLayer();"><img src="' + this.imageURL + 'iw_close.gif" border="0" /></a></div></div>';
var contentDiv = top.document.createElement("div");
contentDiv.style.width = (width - 2) + "px";
contentDiv.style.height = (height - 28) + "px";
if (contentType == 2) {
var temp = "<iframe width='100%' style='height:" + (height - 28) + "px' name='openWinLayerIframe' id='openWinLayerIframe' src='" + htmlStr + "' frameborder='0' scrolling='" + 'auto' + "'></iframe>";
contentDiv.innerHTML = temp;
} else {
contentDiv.innerHTML = htmlStr;
}
var container = document.createElement("div");
container.id = "openWinLayerDIV";
container.style.width = width + "px";
container.style.height = height + "px";
container.style.position = "absolute";
container.style.zIndex = 100;
container.style.border = "5px solid #abbed8";
container.style.fontSize = "13px";
container.style.opacity = "0.98";
container.style.filter = 'alpha(opacity=98)';
container.style.top = (((document.documentElement.clientHeight - height) / 2) + document.documentElement.scrollTop) + "px";
container.style.left = (document.documentElement.clientWidth - width) / 2 + "px";
container.style.backgroundColor = "#fff";
container.innerHTML = title;
container.appendChild(contentDiv);
document.body.appendChild(container);
};
win.prototype.closeWinLayer = function()
{
var _openLayer = top.document.getElementById("openWinLayerDIV");
if (_openLayer != null) {
_openLayer.parentNode.removeChild(_openLayer);
}
var _openLayer_maxmin = top.document.getElementById("openWinLayerDIV_maxmin");
if (_openLayer_maxmin != null) {
_openLayer_maxmin.parentNode.removeChild(_openLayer_maxmin);
}
};
win.prototype.minWinLayer = function(title)
{
var _openLayer = top.document.getElementById("openWinLayerDIV");
if (_openLayer != null) {
_openLayer.style.display = "none";
}
var title = '<div onmousedown=\'drag(document.getElementById("openWinLayerDIV_maxmin"),event)\' style="height:24px;background:#2b98cd;color:#FFF;cursor:move;"><div style="float:left;width:auto;padding-left:10px;height:24px;line-height:24px;font-size:12px;font-weight:bold;">' + title + '</div><div style="float:right;padding-right:4px;padding-top:3px;"><a style="cursor:pointer;" onclick="win.maxWinLayer();"><img src="' + this.imageURL + 'iw_max.gif" border="0" /></a><a><img src="' + this.nullUrl + 'null.gif" width="5" height="14" border="0" /></a><a style="cursor:pointer;" onclick="win.closeWinLayer();"><img src="' + this.imageURL + 'iw_close.gif" border="0" /></a></div></div>';
var contentDiv = top.document.createElement("div");
contentDiv.id = "openWinLayerDIV_maxmin";
contentDiv.style.width = "200px";
contentDiv.style.height = "24px";
contentDiv.style.border = "2px solid #abbed8";
contentDiv.style.position = "absolute";
contentDiv.style.zIndex = 100;
contentDiv.style.fontSize = "13px";
contentDiv.style.top = ((document.documentElement.clientHeight - 40) + document.documentElement.scrollTop) + "px";
contentDiv.style.left = "10px";
contentDiv.innerHTML = title;
document.body.appendChild(contentDiv);
};
win.prototype.maxWinLayer = function()
{
var _openLayer_maxmin = top.document.getElementById("openWinLayerDIV_maxmin");
if (_openLayer_maxmin != null) {
_openLayer_maxmin.parentNode.removeChild(_openLayer_maxmin);
}
var _openLayer = top.document.getElementById("openWinLayerDIV");
if (_openLayer != null) {
_openLayer.style.display = "block";
}
};
var win = new win();//创建win对象
//调用:
//win.openWinLayer("窗口名称","http://www.baidu.com",300,150,2,window,null);
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值