第一次发表文章,有什么写不好的地方请多多包涵,另外想借此机会认识一些从事web设计的朋友,tangzehuan@sohu.com qq 37878073
ie5.5和nn6以上的浏览器支持 frame ,iframe对象的allowtransparency 方法,如果某对象的背景颜色设置为transparency的,它将继承包含它容器的特性。我们可以通过这个特性实现透明背景的开/关。
代码如下:
a.html如下:
<html><head><title></title>
<meta http-equiv=content-type content="text/html; charset=gb2312">
</head>
<body style="background-color: transparent">
<h1>透明文档</h1>
<p>此iframe无背景颜色</p>
<p>body:<br><body style="background-color:transparent"></p></body></html>
b.html如下:
<html><head><title></title>
<meta http-equiv=content-type content="text/html; charset=gb2312">
</head>
<body style="background-color: transparent">
<h1>透明文档</h1>
<p>此iframe 设为绿色。</p>
<p>body: <br><body style="background-color:transparent"></p></body></html>
如果a.html透明的,它将继承iframe的背景颜色 如果容器iframe也是透明的,a.html将继承iframe的父容器的颜色,如果一个对象不透明,它将覆盖其容器的颜色,默认是透明的。
internet explorer 5.5 以上版本允许你设置透明属性,通过设置是否可被透明,你可以改变背景的颜色。[在不设置透明属性的情况下,默认背景颜色为白色]
iframe定义如下:
<iframe id="frame1" src="a.html" allowtransparency="true" height=180 width=300> </iframe> <iframe id="frame2" src="b.html" allowtransparency="true" style="background-color:#459800" height=180 width=300> </iframe>
按钮定义如下:
<input type="button" value="不透明" onclick="turntransparencyoff()"> <input type="button" value="透明" onclick="turntransparencyon()">
<script>
//函数turntransparencyoff():
function turntransparencyoff()
{ document.all.frame1.allowtransparency = false; document.all.frame2.allowtransparency = false; }
//函数turntransparencyon():
function turntransparencyon()
{ document.all.frame1.allowtransparency = true; document.all.frame2.allowtransparency = true; }
</script>