普元日记---HTML5底部遮罩层
来源:互联网 发布:理光软件研究所 户口 编辑:程序博客网 时间:2024/05/16 15:56
<script type="text/javascript">
var docEle = function()
{
return document.getElementById(arguments[0]) || false;
}
function openNewDiv(_id)
{
var m = "mask";
if (docEle(_id)) document.body.removeChild(docEle(_id));
if (docEle(m)) document.body.removeChild(docEle(m));
//mask遮罩层
var newMask = document.createElement("div");
newMask.id = m;
newMask.style.position = "absolute";
newMask.style.zIndex = "1";
_scrollWidth = Math.max(document.body.scrollWidth,document.documentElement.scrollWidth);
_scrollHeight = Math.max(document.body.scrollHeight,document.documentElement.scrollHeight);
// newMask.style.width = _scrollWidth + "px";
// newMask.style.height = _scrollHeight + "px"; 实现全屏遮罩
newMask.style.width = document.body.clientWidth + "px";
newMask.style.height = 200 + "px";
// newMask.style.top = "0px";
//newMask.style.left = "0px";
newMask.style.top = (document.body.scrollTop + document.body.clientHeight / 2 - 200 / 2) + "px";
newMask.style.left = "0px";
newMask.style.background = "#33393C";
newMask.style.filter = "alpha(opacity=40)";
newMask.style.opacity = "0.40";
document.body.appendChild(newMask);
//新弹出层
var newDiv = document.createElement("div");
newDiv.id = _id;
newDiv.style.position = "absolute";
newDiv.style.zIndex = "9999";
newDivWidth = 400;
newDivHeight = 200;
newDiv.style.width = newDivWidth + "px";
newDiv.style.height = newDivHeight + "px";
newDiv.style.top = (document.body.scrollTop + document.body.clientHeight/2 - newDivHeight/2) + "px";
newDiv.style.left = (document.body.scrollLeft + document.body.clientWidth/2 - newDivWidth/2) + "px";
newDiv.style.background = "#EFEFEF";
newDiv.style.border = "1px solid #860001";
newDiv.style.padding = "5px";
newDiv.innerHTML = "弹出层内容 ";
//创建一个图片
var img = document.createElement("img");
img.id = "newimg";
img.style.width = "100px";
img.style.height = "100px";
img.src = "pic325.jpg";
newDiv.appendChild(img);
document.body.appendChild(newDiv);
//弹出层底部居中
function newDivCenter()
{
newDiv.style.top = (document.body.scrollTop + document.body.clientHeight/2 + newDivHeight/2) + "px";
newDiv.style.left = (document.body.scrollLeft + document.body.clientWidth / 2 - newDivWidth / 2) + "px";
//遮罩层也底部居中这样达到可以与弹出层一致的动作
newMask.style.top = (document.body.scrollTop + document.body.clientHeight / 2 + newDivHeight / 2) + "px";
newMask.style.left = "0px";
}
if(document.all)
{
window.attachEvent("onscroll",newDivCenter);
}
else
{
window.addEventListener('scroll',newDivCenter,false);
}
//关闭新图层和mask遮罩层
var newA = document.createElement("a");
newA.href = "#";
newA.innerHTML = "关闭";
newA.onclick = function()
{
if(document.all)
{
window.detachEvent("onscroll",newDivCenter);
}
else
{
window.removeEventListener('scroll',newDivCenter,false);
}
document.body.removeChild(docEle(_id));
document.body.removeChild(docEle(m));
return false;
}
newDiv.appendChild(newA);
}
</script>
<body>
<a onclick="openNewDiv('newDiv');return false;" style="cursor:pointer">显示弹层</a>
</body>
var docEle = function()
{
return document.getElementById(arguments[0]) || false;
}
function openNewDiv(_id)
{
var m = "mask";
if (docEle(_id)) document.body.removeChild(docEle(_id));
if (docEle(m)) document.body.removeChild(docEle(m));
//mask遮罩层
var newMask = document.createElement("div");
newMask.id = m;
newMask.style.position = "absolute";
newMask.style.zIndex = "1";
_scrollWidth = Math.max(document.body.scrollWidth,document.documentElement.scrollWidth);
_scrollHeight = Math.max(document.body.scrollHeight,document.documentElement.scrollHeight);
// newMask.style.width = _scrollWidth + "px";
// newMask.style.height = _scrollHeight + "px"; 实现全屏遮罩
newMask.style.width = document.body.clientWidth + "px";
newMask.style.height = 200 + "px";
// newMask.style.top = "0px";
//newMask.style.left = "0px";
newMask.style.top = (document.body.scrollTop + document.body.clientHeight / 2 - 200 / 2) + "px";
newMask.style.left = "0px";
newMask.style.background = "#33393C";
newMask.style.filter = "alpha(opacity=40)";
newMask.style.opacity = "0.40";
document.body.appendChild(newMask);
//新弹出层
var newDiv = document.createElement("div");
newDiv.id = _id;
newDiv.style.position = "absolute";
newDiv.style.zIndex = "9999";
newDivWidth = 400;
newDivHeight = 200;
newDiv.style.width = newDivWidth + "px";
newDiv.style.height = newDivHeight + "px";
newDiv.style.top = (document.body.scrollTop + document.body.clientHeight/2 - newDivHeight/2) + "px";
newDiv.style.left = (document.body.scrollLeft + document.body.clientWidth/2 - newDivWidth/2) + "px";
newDiv.style.background = "#EFEFEF";
newDiv.style.border = "1px solid #860001";
newDiv.style.padding = "5px";
newDiv.innerHTML = "弹出层内容 ";
//创建一个图片
var img = document.createElement("img");
img.id = "newimg";
img.style.width = "100px";
img.style.height = "100px";
img.src = "pic325.jpg";
newDiv.appendChild(img);
document.body.appendChild(newDiv);
//弹出层底部居中
function newDivCenter()
{
newDiv.style.top = (document.body.scrollTop + document.body.clientHeight/2 + newDivHeight/2) + "px";
newDiv.style.left = (document.body.scrollLeft + document.body.clientWidth / 2 - newDivWidth / 2) + "px";
//遮罩层也底部居中这样达到可以与弹出层一致的动作
newMask.style.top = (document.body.scrollTop + document.body.clientHeight / 2 + newDivHeight / 2) + "px";
newMask.style.left = "0px";
}
if(document.all)
{
window.attachEvent("onscroll",newDivCenter);
}
else
{
window.addEventListener('scroll',newDivCenter,false);
}
//关闭新图层和mask遮罩层
var newA = document.createElement("a");
newA.href = "#";
newA.innerHTML = "关闭";
newA.onclick = function()
{
if(document.all)
{
window.detachEvent("onscroll",newDivCenter);
}
else
{
window.removeEventListener('scroll',newDivCenter,false);
}
document.body.removeChild(docEle(_id));
document.body.removeChild(docEle(m));
return false;
}
newDiv.appendChild(newA);
}
</script>
<body>
<a onclick="openNewDiv('newDiv');return false;" style="cursor:pointer">显示弹层</a>
</body>
0 0
- 普元日记---HTML5底部遮罩层
- 普元日记--自定义底部遮罩层
- 普元日记
- 普元日记
- 普元日记---js基本操作
- 普元日记-页面之间传递参数
- Html5-底部菜单实现
- 普元日记---动态添加的控件(index.html)
- 学习日记-html5
- 学习日记-HTML5-3
- 学习日记-HTML5-4
- HTML5 固定底部的footer功能栏
- HTML5,指定内容滚动到底部固定
- html5 头和底部导航固定
- 普元日记----slide滑动时与Div的滑动对应起来
- 普元日记--动态添加控件跳转页(shutcut.html)
- 2017.01.16 学习日记-享元模式
- HTML5学习日记—拖放特性
- 1094. The Largest Generation (25)
- 子网划分的两个例子 怎么算网络号和广播地址
- 同一个账号只能一处登录
- Equinox OSGi系列之一 Equinox入门
- 我的openwrt学习笔记(九):开发板访问虚拟机 ubuntu linux 文件方法
- 普元日记---HTML5底部遮罩层
- 如何处理word转pdf格式的转换
- 解决imageView加载图片时候造成内存溢出的问题
- TCP 第三次握手失败
- js 返回上一页和刷新
- python—networkx:在一张图中画出多个子图
- HAL硬件抽象层笔记
- 单例模式
- (转)verilog for循环