闲来无事把项目里很土的弹窗改成了遮罩层显示感觉效果好点了上代码
父页面
代码如下:<div id=
newDiv
style="display: none;"><%@include file=
/WEB
INF/jsp/infobackup/martyr/printCertDia
jsp
%><%
<jsp:include page="/WEB
INF/jsp/infobackup/martyr/printCertDia
jsp" flush=”true”/>
%></div>printCertDia
jsp 便是要显示的最上层jsp
如果用jsp:include 页面便会报错
至于为什么还没研究
可能和加载顺序有关
(在给标签变量取名字时候
如果变量和id名一样时候
js也会报错
要避免)在父页面添加触发显示遮罩层js
在这里创建一个div和body一样大小
这样就可以把整个页面全部盖住了
style
zIndex 来控制覆盖的先后顺序(层级)style
filter
style
opacity 控制显示透明°
代码如下://mask遮罩层var newMask = document
createElement("div");newMask
id = m;newMask
style
position = "absolute";newMask
style
zIndex = "
";_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
top = "
px";newMask
style
left = "
px";newMask
style
background = "#
";newMask
style
filter = "alpha(opacity=
)";newMask
style
opacity = "
";document
body
appendChild(newMask);js控制父页面已经定义好的div显示
代码如下:newDiv=document
getElementById("newDiv
");// var newDiv = document
createElement("div");// newDiv
id = _id;newDiv
style
position = "absolute";newDiv
style
zIndex = "
";newDivWidth =
;newDivHeight =
;newDiv
style
width = newDivWidth + "px";newDiv
style
height = newDivHeight + "px";newDiv
style
top = (document
body
scrollTop + document
body
clientHeight /
newDivHeight /
) + "px";newDiv
style
left = (document
body
scrollLeft + document
body
clientWidth /
newDivWidth /
) + "px";newDiv
style
background = "#F
F
EF";newDiv
style
border = "
px solid #
";newDiv
style
padding = "
px";newDiv
style
display=
;js控制父页面div滚动居中
attachEvent
addEventListener 对scroll 添加处理事件 newDivCenter代码如下:function newDivCenter() {newDiv
style
top = (document
body
scrollTop + document
body
clientHeight /
newDivHeight /
) + "px";newDiv
style
left = (document
body
scrollLeft + document
body
clientWidth /
newDivWidth /
) + "px";}if (document
all) {window
attachEvent("onscroll"
newDivCenter);}else {window
addEventListener(
scroll
newDivCenter
false);}动态给父页面div添加关闭图层和遮罩层(需要修改)
代码如下: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("newDiv
"));document
body
removeChild(docEle(m));document
getElementById("certImg")
style
display=
;return false;}newDiv
appendChild(newA);