始终拉伸填满窗口的背景及层的透明

既然有的浏览器不支持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 >
 
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值