既然有的浏览器不支持fixed,干脆把它去掉,倒简化了代码。另外也去掉了expression的表达,而用window.onresize来触发resetSizes事件来代替,虽然代码量增加了,但是还是很值得的,毕竟expression并不能让人省心。还加了两个测试层,这格式正宗的透明层,使用滤镜来完成,注意一定要使用包含透明度的png图片,其他图片不行的哦!在实际使用中,请把这两个透明测试层的代码换成你自己的代码,其他的结构不要修改,代码如下:
<
html
>
< head >
< title > 始终拉伸填满窗口的背景及层的透明--author:shosh </ title >
< style >
<!--
body { padding : 0 ; margin : 0 ; overflow : hidden }
p { text-indent : 2em }
#shoshBG { position : absolute ; left : 0 ; top : 0 ; z-index : -1000 ; filter : alpha(opacity=30) ; }
#ShoshMainBody { overflow : auto ; position : abosulute ; left : 0 ; top : 0 ; width : 100% ; height : 100% ; }
-->
</ style >
</ head >
< body >
< img src ="http://www.cnitblog.com/images/cnitblog_com/shosh/shosh_card.jpg" id ="shoshBG" onload =resetSizes() GALLERYIMG ="no" >
< div id =ShoshMainBody >< div ID ="ScrollHelpDiv" style ="background-image:url(about:blank?DesignerShosh);" >
<!-- 把网页内容放在后面哦。 -->
< div style ="background:none transparent scroll repeat 0% 0%;color:brown;height:400;width:500;border:groove 2px red;FILTER: progid:DXImageTransform.Microsoft.AlphaImageLoader(src='http://www.cnitblog.com/images/cnitblog_com/shosh/dimgold.png',sizingMethod='scale');" > 透明测试层1,缩小窗口可产生滚动条 </ div >
< div style ="position:absolute;top:100;left:200;background:none transparent scroll repeat 0% 0%;color:green;height:600;width:500;border:groove 2px red;FILTER: progid:DXImageTransform.Microsoft.AlphaImageLoader(src='http://www.cnitblog.com/images/cnitblog_com/shosh/dimgreen.png',sizingMethod='scale');" > 透明测试层2,缩小窗口可产生滚动条 </ div >
<!-- 把网页内容放在前面哦。 -->
</ div ></ div >
< script >
<!--
function resetSizes()
{
var theBody = document.getElementById( " ShoshMainBody " );
var theBg = document.getElementById( " shoshBG " );
if (theBg && theBody)
{
var minus = theBody.scrollHeight > theBody.clientHeight ? 15 : 0 ;
theBg.style.width = document.body.clientWidth - minus;
minus = theBody.scrollWidth > theBody.clientWidth ? 15 : 0 ;
theBg.style.height = document.body.clientHeight - minus;
}
var scrHelp = document.getElementById( " ScrollHelpDiv " );
if (scrHelp)
{
with (scrHelp.style)
{
width = theBody.scrollWidth;
height = theBody.scrollHeight;
}
}
}
resetSizes();
window.onresize = resetSizes
// by shosh whose blog is http://www.cnitblog.com/shosh-->
</ script >
</ body >
</ html >
< head >
< title > 始终拉伸填满窗口的背景及层的透明--author:shosh </ title >
< style >
<!--
body { padding : 0 ; margin : 0 ; overflow : hidden }
p { text-indent : 2em }
#shoshBG { position : absolute ; left : 0 ; top : 0 ; z-index : -1000 ; filter : alpha(opacity=30) ; }
#ShoshMainBody { overflow : auto ; position : abosulute ; left : 0 ; top : 0 ; width : 100% ; height : 100% ; }
-->
</ style >
</ head >
< body >
< img src ="http://www.cnitblog.com/images/cnitblog_com/shosh/shosh_card.jpg" id ="shoshBG" onload =resetSizes() GALLERYIMG ="no" >
< div id =ShoshMainBody >< div ID ="ScrollHelpDiv" style ="background-image:url(about:blank?DesignerShosh);" >
<!-- 把网页内容放在后面哦。 -->
< div style ="background:none transparent scroll repeat 0% 0%;color:brown;height:400;width:500;border:groove 2px red;FILTER: progid:DXImageTransform.Microsoft.AlphaImageLoader(src='http://www.cnitblog.com/images/cnitblog_com/shosh/dimgold.png',sizingMethod='scale');" > 透明测试层1,缩小窗口可产生滚动条 </ div >
< div style ="position:absolute;top:100;left:200;background:none transparent scroll repeat 0% 0%;color:green;height:600;width:500;border:groove 2px red;FILTER: progid:DXImageTransform.Microsoft.AlphaImageLoader(src='http://www.cnitblog.com/images/cnitblog_com/shosh/dimgreen.png',sizingMethod='scale');" > 透明测试层2,缩小窗口可产生滚动条 </ div >
<!-- 把网页内容放在前面哦。 -->
</ div ></ div >
< script >
<!--
function resetSizes()
{
var theBody = document.getElementById( " ShoshMainBody " );
var theBg = document.getElementById( " shoshBG " );
if (theBg && theBody)
{
var minus = theBody.scrollHeight > theBody.clientHeight ? 15 : 0 ;
theBg.style.width = document.body.clientWidth - minus;
minus = theBody.scrollWidth > theBody.clientWidth ? 15 : 0 ;
theBg.style.height = document.body.clientHeight - minus;
}
var scrHelp = document.getElementById( " ScrollHelpDiv " );
if (scrHelp)
{
with (scrHelp.style)
{
width = theBody.scrollWidth;
height = theBody.scrollHeight;
}
}
}
resetSizes();
window.onresize = resetSizes
// by shosh whose blog is http://www.cnitblog.com/shosh-->
</ script >
</ body >
</ html >