javascript控制Div层透明属性,由浅变深逐渐显示,由深变浅逐渐消失

javascript控制Div层透明属性,由浅变深逐渐显示,由深变浅逐渐消失

搬运的留着以后自己看!

复制下面蓝色的代码保存为html格式的文件,使用网页浏览器浏览效果

代码支持IE6、7、8/firefox/Chrome浏览器

 

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>javascript控制Div层透明属性,由浅变深逐渐显示,由深变浅逐渐消失</title>
<script>
var SysIsIE;
var ua = navigator.userAgent.toLowerCase();
var s;(s = ua.match(/msie ([\d.]+)/)) ? SysIsIE = s[1] : 0;

function Q(s){
 return document.getElementById(s);
}
function dvck(){
 idstr='tian';
 e=Q(idstr);
 if(e){
  e.parentNode.removeChild(e);
 }
 var div=document.createElement("div");
 div.style.position="absolute";
 div.style.top='10%';
 div.style.left='40%';
 div.style.cssText='filter: alpha(opacity=10);opacity:0.1;position:absolute;top:50%;left:50%;width:544px;height:354px;margin-top:-177px;margin-left:-272px;;background-color:#000';
 div.id=idstr;
 //div.innerHTML='<img src="i.jpg" οnclick="cleand(\''+idstr+'\')" />';
 div.innerHTML='<p style="color:#fff;text-align:center;">div层显示的内容,author:<a href="http://hi.baidu.com/bluid" style="color:#FBFC4D">bluid</a><br><br><br><br><br><a href="javascript:cleand(\''+idstr+'\')" style="color:#FEF8C3">关闭</a></p>';
 document.body.appendChild(div);
 if (SysIsIE)
  dcbIE(idstr,'+');
 else
  dcboth(idstr,'+');
}
function dcbIE(s,j){
 o=Q(s);
 opc=parseInt(o.filters.alpha.opacity);
 if(j=='+'){
  if(opc<100){
   o.filters.alpha.opacity=(opc+10)+'';
   setTimeout("dcbIE('"+s+"','"+j+"')",100);
  }
 }else if(j=='-'){
  if(opc>0){
   o.filters.alpha.opacity=(opc-10)+'';
   setTimeout("cleand('"+s+"','"+j+"')",100);
  }
 }
}
function dcboth(s,j){
 o=Q(s);
 opc=parseFloat(o.style.opacity);
 if(j=='+'){
  if(opc<1){
   o.style.opacity=(opc+0.1)+'';
   //setInterval("dcboth('"+s+"')",3000);
   setTimeout("dcboth('"+s+"','"+j+"')",100);
  }
 }else if(j=='-'){
  if(opc>0){
   o.style.opacity=(opc-0.1)+'';
   setTimeout("cleand('"+s+"','"+j+"')",100);
  }
 }
}


function cleand(s){
 if (SysIsIE){
  dcbIE(s,'-');
 }else{
  dcboth(s,'-');
 }
}
</script>
</head>

<body>
<div><br><br>
<p style="font-size:14px">javascript控制Div层透明属性,由浅变深逐渐显示,由深变浅逐渐消失.</p><br><br>
<br><br><br>
<p>单击'click'显示层,由浅变深逐渐显示</p><br><br><br><br>
<a href="javascript:dvck()">click</a><br><br><br><br>
<p>在显示的层上单击,可以由深变浅逐渐消失</p>
<br><br><br>
<p>
<!-- #BeginDate format:Am3m -->02/11/2011  16:17<!-- #EndDate -->  --- author:<a href=" http://hi.baidu.com/bluid">bluid</a>
</p>
<br><br><br><br>
<br><br>
</div>
</body>
</html>
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值