WEB页面实现淡入淡出菜单

(本文适合菜级网页制作者或初级WEB编程者阅读参考)
下面的程序还是简单的测试版。需要编程的整个思路和具体分析步骤的请Email到[email protected]

 1<html>
 2<head>
 3<meta content="text/html; charset=utf-8" http-equiv="Content-Type"/>
 4<title> 淡入淡出菜单演示 </title>
 5<style>   
 6.sml_menu {font-size: 9pt; color: white; cursor: hand; font-family: Tahoma;}   
 7.font3 {font-size: 10.5pt; color: 147e19; font-family: Courier New;}   
 8.menuitem {font-size: 10.5pt; color: white; cursor: default; font-family: Courier New;}   
 9</style>
10<script language="javascript">   
11//LiveMenu Ver1.0 by [email protected]   
12//2000.11   
13var intDelay=50; //设置菜单显示速度,越大越慢,不超过100为好   
14var intInterval=5; //每次更改的透明度,最好小于10   
15//以下代码需要改的地方可以更改   
16function MenuClick()   
17{   
18if (LayerMenu.style.display=="")   
19{   
20LayerMenu.style.display="none"; //当菜单显示的时候单击就关闭菜单   
21}   
22else{   
23LayerMenu.filters.alpha.opacity=0;   
24LayerMenu.style.display="";   
25GradientShow(); //淡入   
26}   
27}   
28  
29function GradientShow() //实现淡入的函数   
30{   
31LayerMenu.filters.alpha.opacity+=intInterval;   
32if (LayerMenu.filters.alpha.opacity<100) setTimeout("GradientShow()",intDelay);   
33}   
34  
35function GradientClose() //实现淡出的函数   
36{   
37LayerMenu.filters.alpha.opacity-=intInterval;   
38if (LayerMenu.filters.alpha.opacity>0) {   
39setTimeout("GradientClose()",intDelay);   
40}   
41else {   
42LayerMenu.style.display="none"; //当看不到菜单层后还需要把这个层隐藏起来   
43}   
44}   
45  
46function ChangeBG() //改变菜单项的背景颜色,这里的两种颜色值可以改为你需要的   
47{   
48oEl=event.srcElement;   
49if (oEl.style.background!="navy") {   
50oEl.style.background="navy";   
51}   
52else {   
53oEl.style.background="#147e19";   
54}   
55}   
56  
57function ItemClick() //在菜单项上单击后打开相应链接   
58{   
59oEl=event.srcElement;   
60oLink=oEl.all.tags( "A" );   
61if( oLink.length )   
62{   
63oLink[0].click();   
64GradientClose();   
65}   
66}   
67</script>
68</head>
69<body onmouseover="GradientClose();">
70<br/>
71<p align="center" class="font3">LiveMenu V1.0 by [email protected]<br/>请查看源代码<br/>   
72请手动设置菜单层或菜单提示层的具体位置<br/>   
73在: style="Position:Absolute;Left:???px;Top:???px;" 处设置</p>
74<!--菜单提示层开始-->
75<div onclick="MenuClick()" style="Position:Absolute;Left:250px;Top:120px;">
76<table border="0" cellpadding="0" cellspacing="0" width="300"><tr><td bgcolor="#147e19" class="sml_menu" height="20" onselectstart="return false;"> Click here to show the menu ... (单击显示菜单)</td></tr></table>
77</div>
78<!--菜单提示层结束-->
79</body>
80<!--菜单层开始-->
81<div id="LayerMenu" oncontextmenu="return false" onmouseover="window.event.cancelBubble = true;" style="Position:Absolute;Left:250px;Top:137px;Display:none;filter:alpha(opacity=0);">
82<!--上面一行的onMouseover事件是很关键的-->
83<table bgcolor="147e19" border="0" cellpadding="0" cellspacing="0">
84<tr><td bgcolor="#f0f0f0" colspan="2" height="1"></td></tr>
85<tr><td bgcolor="navy" valign="bottom" width="20"></td>
86<td>
87<table border="0" cellpadding="0" cellspacing="0" onclick="ItemClick();" onmouseout="ChangeBG();" onmouseover="ChangeBG();" onselectstart="return false;" width="200">
88<tr><td class="menuitem" height="20" style="background: 147e19;"><a href="/First"></a>1.The First Menu Item</td></tr>
89<tr><td class="menuitem" height="20" style="background: 147e19;"><a href="/Second"></a>2.The Second Menu Item</td></tr>
90<tr><td class="menuitem" height="20" style="background: 147e19;">3.The Third Menu Item</td></tr>
91<tr><td class="menuitem" height="20" style="background: 147e19;">4.The Fourth Menu Item</td></tr>
92</table>
93</td></tr>
94</table>
95</div>
96<!--菜单层结束-->
97</html>
Published At
Categories with Web编程
Tagged with
comments powered by Disqus