javascript控制Div層透明屬性由淺變深由深變淺逐漸顯示
更新時間:2013年11月12日 17:25:35 作者:
控制Div層透明屬性,由淺變深逐漸顯示,由深變淺逐漸消失,具體實現(xiàn)代碼如下,喜歡的朋友可以感受下
搬運(yùn)的留著以后自己看!
復(fù)制下面藍(lán)色的代碼保存為html格式的文件,使用網(wǎng)頁瀏覽器瀏覽效果
代碼支持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" onclick="cleand(\''+idstr+'\')" />';
div.innerHTML='<p style="color:#fff;text-align:center;">div層顯示的內(nèi)容,author:<a style="color:#FBFC4D">bluid</a><br><br><br><br><br><a href="javascript:cleand(\''+idstr+'\')" style="color:#FEF8C3">關(guān)閉</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 >bluid</a>
</p>
<br><br><br><br>
<br><br>
</div>
</body>
</html>
復(fù)制下面藍(lán)色的代碼保存為html格式的文件,使用網(wǎng)頁瀏覽器瀏覽效果
代碼支持IE6、7、8/firefox/Chrome瀏覽器
復(fù)制代碼 代碼如下:
<!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" onclick="cleand(\''+idstr+'\')" />';
div.innerHTML='<p style="color:#fff;text-align:center;">div層顯示的內(nèi)容,author:<a style="color:#FBFC4D">bluid</a><br><br><br><br><br><a href="javascript:cleand(\''+idstr+'\')" style="color:#FEF8C3">關(guān)閉</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 >bluid</a>
</p>
<br><br><br><br>
<br><br>
</div>
</body>
</html>
您可能感興趣的文章:
- JavaScript動態(tài)改變div屬性的實現(xiàn)方法
- JavaScript動態(tài)創(chuàng)建div屬性和樣式示例代碼
- javascript中offset、client、scroll的屬性總結(jié)
- javascript通過獲取html標(biāo)簽屬性class實現(xiàn)多選項卡的方法
- JavaScript對象屬性檢查、增加、刪除、訪問操作實例
- JavaScript獲取并更改input標(biāo)簽name屬性的方法
- JavaScript正則表達(dá)式之multiline屬性的應(yīng)用
- JavaScript中Math.SQRT2屬性的使用詳解
- Javascript控制div屬性動態(tài)變化實例分析
相關(guān)文章
JavaScript實現(xiàn)扯網(wǎng)動畫效果的示例代碼
這篇文章主要為大家詳細(xì)介紹了如何利用JavaScript語言實現(xiàn)扯網(wǎng)動畫效果,文中的示例代碼講解詳細(xì),對我們學(xué)習(xí)JS有一定的幫助,需要的可以參考一下2022-06-06JavaScript sort數(shù)組排序方法和自我實現(xiàn)排序方法小結(jié)
這篇文章主要介紹了JavaScript sort數(shù)組排序方法和自我實現(xiàn)排序方法小結(jié)的相關(guān)資料,非常不錯具有參考借鑒價值,需要的朋友可以參考下2016-06-06input+select(multiple) 實現(xiàn)下拉框輸入值
昨天做一個網(wǎng)站時,需要實現(xiàn)下拉框能夠輸入,從功能上講是要實現(xiàn)用戶在文本框輸入值時,能夠從后讀出數(shù)據(jù)彈出下拉選項2009-05-05在mpvue框架中使用Vant WeappUI組件庫的注意事項【推進(jìn)】
這篇文章主要介紹了在mpvue框架中使用Vant WeappUI組件庫的注意事項,本文給大家提到了引入組件庫的兩種方法,需要的朋友可以參考下2019-06-06