自制弹出式内容框JS代码
2008-06-20 21:04
274 查看
//Xingmai命名空间
if(!Xingmai)
var Xingmai = {};
//内容窗口
Xingmai.ContentBox =
{
//创建窗口
CreateBox : function()
{
//创建窗体
var contentBox = {};
//ID
contentBox.ID = null;
//窗口Title
contentBox.Title = null;
//窗口宽度
contentBox.Width = null;
//窗口高度
contentBox.Height = null;
//窗口左像素
contentBox.Left = null;
//窗口顶像素
contentBox.Top = null;
//Class定义
contentBox.ClassName= null;
//默认值
contentBox.Common = {
Width : 500,
Height : 400,
Left : (document.documentElement.clientWidth - contentBox.Width)/2 +
document.documentElement.scrollLeft,//有问题
Top :
(document.documentElement.clientHeight - contentBox.Height)/2 +
document.documentElement.scrollTop //有问题
};
//创建BOX
contentBox.Create = function()
{
//alert("a");
//创建主要界面
var newBox = document.createElement("div");
newBox.setAttribute("id", contentBox.ID);
with(newBox.style)
{
position = "absolute";
zIndex = "9999";
width = contentBox.Width + "px";
height = contentBox.Height + "px";
top = contentBox.Top;
left = contentBox.Left;
}
//newBox.setAttribute("style", "width : " + contentBox.Width + "px; height : " + contentBox.Height + "px;");
if(contentBox.ClassName!=null)
newBox.setAttribute("className", contentBox.ClassName);
//创建标题栏和删除按钮
var titleSpan = document.createElement("div");
with(titleSpan.style)
{
height = "20px";
textAlign = "left";
verticalAlign = "middle";
}
//titleSpan.setAttribute("style", "height : " + "35" + "px;");
titleSpan.setAttribute("class","contentTitleSpan");
var spanDiv = document.createElement("div");
with(spanDiv.style)
{
width = contentBox.Width - 30 + "px";
styleFloat = "left";
textAlign = "left";
}
spanDiv.appendChild(document.createTextNode(contentBox.Title));
titleSpan.appendChild(spanDiv);
var closeDiv = document.createElement("div");
with(closeDiv.style)
{
width = "20px";
styleFloat = "right";
textAlign = "right";
}
var closeButton = document.createElement("a");
closeButton.setAttribute("href", "#");
closeButton.appendChild(document.createTextNode("×"));
$addHandler(closeButton,"click", function(){Xingmai.ContentBox.KillBox(contentBox.ID);});
closeDiv.appendChild(closeButton)
titleSpan.appendChild(closeDiv);
newBox.appendChild(titleSpan);
//创建Iframe
var iframe = document.createElement("iframe");
iframe.setAttribute("class","contentIframe")
iframe.setAttribute("src" , contentBox.Url);
iframe.setAttribute("frameborder","0",0);
iframe.setAttribute("scrolling","no");
with(iframe.style)
{
border = "0";
width = "100%";
height = (contentBox.Height - 20) + "px";
}
newBox.appendChild(iframe);
return newBox;
};
//创建ID
contentBox.CreateID = function()
{
var now = new Date();
return "ContentBox" + now.getFullYear() + now.getMonth() + now.getDay()
+ now.getHours() + now.getMinutes() + now.getSeconds() +
now.getMilliseconds();
};
//显示窗口
contentBox.Show = function()
{
//处理默认值
contentBox.ID = contentBox.ID == null ? contentBox.CreateID() : contentBox.ID;
contentBox.Title = contentBox.Title == null ? "内容系统窗口" : contentBox.Title;
contentBox.Url = contentBox.Url == null ? "about:blank" : contentBox.Url;
if(isNaN(contentBox.Width)||contentBox.Width == null)
contentBox.Width = contentBox.Common.Width;
if(isNaN(contentBox.Height)||contentBox.Height == null)
contentBox.Height = contentBox.Common.Height;
if(isNaN(contentBox.Left)||contentBox.Left == null)
contentBox.Left = contentBox.Common.Left;
if(isNaN(contentBox.Top)||contentBox.Top == null)
contentBox.Top = contentBox.Common.Top;
//创建窗口并显示
var add = contentBox.Create();
document.getElementsByTagName("body").item(0).appendChild(add);
};
return contentBox;
},
//删除窗口
KillBox : function(id)
{
var box= document.getElementById(id);
if(box)
box.parentNode.removeChild(box);
}
};
if(!Xingmai)
var Xingmai = {};
//内容窗口
Xingmai.ContentBox =
{
//创建窗口
CreateBox : function()
{
//创建窗体
var contentBox = {};
//ID
contentBox.ID = null;
//窗口Title
contentBox.Title = null;
//窗口宽度
contentBox.Width = null;
//窗口高度
contentBox.Height = null;
//窗口左像素
contentBox.Left = null;
//窗口顶像素
contentBox.Top = null;
//Class定义
contentBox.ClassName= null;
//默认值
contentBox.Common = {
Width : 500,
Height : 400,
Left : (document.documentElement.clientWidth - contentBox.Width)/2 +
document.documentElement.scrollLeft,//有问题
Top :
(document.documentElement.clientHeight - contentBox.Height)/2 +
document.documentElement.scrollTop //有问题
};
//创建BOX
contentBox.Create = function()
{
//alert("a");
//创建主要界面
var newBox = document.createElement("div");
newBox.setAttribute("id", contentBox.ID);
with(newBox.style)
{
position = "absolute";
zIndex = "9999";
width = contentBox.Width + "px";
height = contentBox.Height + "px";
top = contentBox.Top;
left = contentBox.Left;
}
//newBox.setAttribute("style", "width : " + contentBox.Width + "px; height : " + contentBox.Height + "px;");
if(contentBox.ClassName!=null)
newBox.setAttribute("className", contentBox.ClassName);
//创建标题栏和删除按钮
var titleSpan = document.createElement("div");
with(titleSpan.style)
{
height = "20px";
textAlign = "left";
verticalAlign = "middle";
}
//titleSpan.setAttribute("style", "height : " + "35" + "px;");
titleSpan.setAttribute("class","contentTitleSpan");
var spanDiv = document.createElement("div");
with(spanDiv.style)
{
width = contentBox.Width - 30 + "px";
styleFloat = "left";
textAlign = "left";
}
spanDiv.appendChild(document.createTextNode(contentBox.Title));
titleSpan.appendChild(spanDiv);
var closeDiv = document.createElement("div");
with(closeDiv.style)
{
width = "20px";
styleFloat = "right";
textAlign = "right";
}
var closeButton = document.createElement("a");
closeButton.setAttribute("href", "#");
closeButton.appendChild(document.createTextNode("×"));
$addHandler(closeButton,"click", function(){Xingmai.ContentBox.KillBox(contentBox.ID);});
closeDiv.appendChild(closeButton)
titleSpan.appendChild(closeDiv);
newBox.appendChild(titleSpan);
//创建Iframe
var iframe = document.createElement("iframe");
iframe.setAttribute("class","contentIframe")
iframe.setAttribute("src" , contentBox.Url);
iframe.setAttribute("frameborder","0",0);
iframe.setAttribute("scrolling","no");
with(iframe.style)
{
border = "0";
width = "100%";
height = (contentBox.Height - 20) + "px";
}
newBox.appendChild(iframe);
return newBox;
};
//创建ID
contentBox.CreateID = function()
{
var now = new Date();
return "ContentBox" + now.getFullYear() + now.getMonth() + now.getDay()
+ now.getHours() + now.getMinutes() + now.getSeconds() +
now.getMilliseconds();
};
//显示窗口
contentBox.Show = function()
{
//处理默认值
contentBox.ID = contentBox.ID == null ? contentBox.CreateID() : contentBox.ID;
contentBox.Title = contentBox.Title == null ? "内容系统窗口" : contentBox.Title;
contentBox.Url = contentBox.Url == null ? "about:blank" : contentBox.Url;
if(isNaN(contentBox.Width)||contentBox.Width == null)
contentBox.Width = contentBox.Common.Width;
if(isNaN(contentBox.Height)||contentBox.Height == null)
contentBox.Height = contentBox.Common.Height;
if(isNaN(contentBox.Left)||contentBox.Left == null)
contentBox.Left = contentBox.Common.Left;
if(isNaN(contentBox.Top)||contentBox.Top == null)
contentBox.Top = contentBox.Common.Top;
//创建窗口并显示
var add = contentBox.Create();
document.getElementsByTagName("body").item(0).appendChild(add);
};
return contentBox;
},
//删除窗口
KillBox : function(id)
{
var box= document.getElementById(id);
if(box)
box.parentNode.removeChild(box);
}
};
相关文章推荐
- JS实现的新浪微博大厅文字内容滚动效果代码
- 实现两个下拉选框内容不一致的JS代码
- js实现当鼠标移到表格上时显示这一格全部内容的代码
- 一段js代码解决网页内容无法复制的问题
- 左右互换内容的JS代码
- 当鼠标滑过文本框自动选中输入框内容JS代码
- jquery.rotate.js实现可选抽奖次数和中奖内容的转盘抽奖代码
- JS获取剪贴板内容的代码
- 纯js集成fck 以及 判断fck内容是否为空的js代码
- 当滚动条滚动到页面底部自动加载增加内容的js代码
- JS实现的另类手风琴效果网页内容切换代码
- JS 页面内容搜索,类似于 Ctrl+F功能的实现代码
- 网站内容禁止复制和粘贴、另存为的js代码
- 如何使用C#在发送往client的内容上加js代码
- js打印WEB页面内容代码大全
- 如何在网页中通过js代码将内容分享到朋友圈?
- js实现鼠标点击input框后里面的内容就消失代码
- JS根据时间内容分组代码
- js复制内容加版权声明代码