使用Dreamweaver中自带的MM_showHideLayers()来显示/隐藏浮动层超级简单而且代码十分少,但是功能很单调,想要让层能够渐隐/渐显,请问该怎么办,如果有高手能在MM_showHideLayers()方法中做些修改实现此功能,那就太好了!function MM_showHideLayers() { //v9.0
var i,p,v,obj,args=MM_showHideLayers.arguments;
for (i=0; i<(args.length-2); i+=3)
with (document) if (getElementById && ((obj=getElementById(args[i]))!=null)) { v=args[i+2];
if (obj.style) { obj=obj.style; v=(v=='show')?'visible':(v=='hide')?'hidden':v; }
obj.visibility=v; }
var i,p,v,obj,args=MM_showHideLayers.arguments;
for (i=0; i<(args.length-2); i+=3)
with (document) if (getElementById && ((obj=getElementById(args[i]))!=null)) { v=args[i+2];
if (obj.style) { obj=obj.style; v=(v=='show')?'visible':(v=='hide')?'hidden':v; }
obj.visibility=v; }
http://www.asp2100.cn/queshow.asp?id=50
<!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=utf-8" />
<title>无标题文档</title>
<style type="text/css">
#divMsg{
width:200px;
height:200px;
color:#FFFFFF;
background-color:#006699;
line-height:200px;
text-align:center;
}
</style>
<script type="text/javascript">
function setOpacity(obj, value){
if(document.all){
if(value == 100){
obj.style.filter = "";
}else{
obj.style.filter = "alpha(opacity=" + value + ")";
}
}else{
obj.style.MozOpacity = value / 100;
}
}
function changeOpacity(obj, startValue, endValue, step, speed){
if(step > 0 && startValue < endValue || step < 0 && startValue > endValue){
setOpacity(obj, endValue);
return;
}
setOpacity(obj, startValue);
setTimeout(function(){changeOpacity(obj, startValue-step, endValue, step, speed);}, speed);
}
function showMsg(){
var msg = document.getElementById("divMsg");
var step = 4, speed = 30;
msg.isShow = !msg.isShow;
if(!msg.isShow){
changeOpacity(msg, 0, 100, -step, speed);
}else{
changeOpacity(msg, 100, 0, step, speed);
}
}
</script>
</head><body>
<div id="divMsg">
测试渐隐/渐显....
</div>
<br />
<input type="button" value=" 显示/隐藏 " onclick="showMsg()" />
</body>
</html>
===============================================================================
<!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=utf-8" />
<title>无标题文档</title>
<style type="text/css">
<!--
#apDiv1 {
position:absolute;
width:175px;
height:112px;
z-index:1;
visibility: hidden;
}
-->
</style>
<script type="text/javascript">
<!--
function DIVShow(dv,ff){
ff=ff+5;
document.getElementById(dv).style.filter="alpha(opacity="+ff+");"
if(ff<100){
window.setTimeout("DIVShow('"+dv+"',"+ff+")",100);
}else{
document.getElementById(dv).style.visibility="show";
}
}
function DIVHide(dv,ff){
ff=ff-5;
document.getElementById(dv).style.filter="alpha(opacity="+ff+");"
if(ff>0){
window.setTimeout("DIVHide('"+dv+"',"+ff+")",100);
}else{
document.getElementById(dv).style.visibility="hidden";
}
}function MM_showHideLayers()
{ //v9.0
var i,p,v,obj,args=MM_showHideLayers.arguments;
for (i=0; i<(args.length-2); i+=3)
with (document) if (getElementById && ((obj=getElementById(args[i]))!=null))
{ v=args[i+2]; if (obj.style) { obj=obj.style; v=(v=='show')?'visible':(v=='hide')?'hidden':v; }
if(v=="show")
{
DIVHide(args[i],100);
}else{
DIVShow(args[i],100);
}
}
}
//-->
</script>
</head><body><table width="300" border="1" cellspacing="0" cellpadding="0">
<tr>
<td onmouseover="MM_showHideLayers('apDiv1','','show')"><!--这里是浮动层,层里放了表格做菜单用的--><div id="apDiv1" onmouseout="MM_showHideLayers('apDiv1','','hide')"><table width="100" border="0" cellspacing="0" cellpadding="0">
<tr>
<td> </td>
</tr>
<tr>
<td bgcolor="#999900"> </td>
</tr>
<tr>
<td bgcolor="#999900">菜单层的内容!</td>
</tr>
</table>
</div>
鼠标移到这里就显示菜单啊!!!</td>
</tr>
</table>
</body></html>
<!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=utf-8" />
<title>无标题文档</title>
<style type="text/css">
<!--
#apDiv1 {
position:absolute;
width:175px;
height:112px;
z-index:1;
visibility: hidden;
}
-->
</style>
<script type="text/javascript">
<!--
function DIVShow(dv,ff){
ff=ff+5;
document.getElementById(dv).style.visibility = "visible";
document.getElementById(dv).style.filter="alpha(opacity="+ff+");"
if(ff <100){
window.setTimeout("DIVShow('"+dv+"',"+ff+")",100);
}
}
function DIVHide(dv,ff){
ff=ff-5;
document.getElementById(dv).style.filter="alpha(opacity="+ff+");"
if(ff>0){
window.setTimeout("DIVHide('"+dv+"',"+ff+")",100);
}else{
document.getElementById(dv).style.visibility="hidden";
}
} function MM_showHideLayers()
{ //v9.0
var i,p,v,obj,args=MM_showHideLayers.arguments;
for (i=0; i <(args.length-2); i+=3)
with (document) if (getElementById && ((obj=getElementById(args[i]))!=null))
{
v=args[i+2]; if (obj.style) { v=(v=='show')?'visible':(v=='hide')?'hidden':v; }
if(args[i+2] != "show" && obj.style.visibility != v)
{
DIVHide(args[i],100);
}else{
DIVShow(args[i],0);
}
}
}
//-->
</script>
</head>
<body>
<!--这里是浮动层,层里放了表格做菜单用的-->
<div id="apDiv1" onmouseout="MM_showHideLayers('apDiv1','','hide')">
<table width="100" border="0" cellspacing="0" cellpadding="0">
<tr>
<td> </td>
</tr>
<tr>
<td bgcolor="#999900"> </td>
</tr>
<tr>
<td bgcolor="#999900">菜单层的内容! </td>
</tr>
</table>
</div>
<table width="300" border="1" cellspacing="0" cellpadding="0">
<tr>
<td onmouseover="MM_showHideLayers('apDiv1','','show')">
鼠标移到这里就显示菜单啊!!! </td>
</tr>
</table>
</body>
</html>
转自:http://www.wearelearn.net/javascript/jsData_12_51/574.html