admin 管理员组

文章数量: 1184232


2024年3月11日发(作者:arm视频解码)

维普资讯

同络天地 KETWORK 主五r ‘宣 

编者按:新年伊始,《电脑知识与技水》杂志又面临新的挑战,如何让每十拦目焘 

加吸引读者.颇让我们花费了诸多 思。网络专栏仍成平稳、求新的姿态面向广 

大读者,力求符合大众化口胃,期期出精品;力求读者在嚼读文章的嗣时,不仅仅 

获得的是乐趣,最重要的是能学刘崭新的知识 

网页特效大放送 

多级滑弓力某萆 

w ̄speying 

经常上阿的朋友可能都去过微软网 

站,对它的导航下拉菜单羡慕不已,可是互 

联网发展至今,遮已不是什么稀奇玩意儿 

了,我们暂且不介绍这屉怎么做的,毕竟好 

东东太多啦!下面介绍的是另

好尔东——多级滑动菜单! 

・个所渭的 

menuv Ifilter:revearrfHns(transitiot ̄= 

23.duration=0.5);padding:2pxl 

</style> 

nonnal、up、down分别定义了鼠标离开、 

移上、按下时显示在菜单项上的样式。 

Mcnu ̄表示鼠标移开菜单列的样式情况。上 

面的代码可插在<head>与</bead>之 

 I。 I

目暖寓寓曩豳曩秘霉墨 

,酶 ,峨韬 辑 《一 

j 栅‘ 叠曲盘- I 

j 莓 i面藉 

{ 

第二步.我们来看下面的JavaScript的 

代码。 

f{f鲢壁 蠖囊’ 曼  i

其中打开网页时菜单列从测览器左下 

角飞上去的效果是由函数bodyload()控制 

的;控制鼠标拖动层的函数是mo ̄e();下面 

从这个例子中我们可以学到一些有关 

每段函数后面都有注释,解释了每段函数的 

功能。 

movef 1 ol卜 

CSS和JayakSclipt的知识,对F拉菜单的制 

作原理和基础的理解有着很大帮助。这种 

菜单的好处就是我们可以用鼠标任意地拖 

动 闲话不说了,下面我们来一步一步学习 

这个菜单是如何做出来的。 

第步:定义CSS样式表 

首先我们根据需要定义菜单项和菜单 

load=bodyload()> 

<SorLpt> 

//闪烁的表格边框 

function flashit() 

f if¨document.al1) 

returl ̄; 

列的CSS层叠样式表 

< ̄lyle> 

if(tdl23.style bordcr( ̄olor=: black ) 

td123.style.borderColor:"#999999 : 

else 

}H,dy,td,a{font—size:9pt;color:black; 

text—de(:oration:Flon ̄ ̄】 

normal【padding:2px 1 

td123.style bordcrColor= black l 

up fpadding:1 px;border".#999999 1 p 

I 

setlnter*'al( flashit() ,50o) 

solid;background:#ccc 

//渐人的效果,改变alpha值 

function high(image1 

{theobject:image,hi曲ligl1ting set- 

down{padding:lpx;border:dbdbdb 

1px ̄olid;background:dbdbdb 1 

维普资讯

^ r羲室 

lnte ̄'al( highlightit(theobject) .100)J 

function low(image) 

NETWORK 

</script> 

</body> 

网络天地 

{clearlnter ̄al(highlighting), 

age.filters alpha.opacity=50I 

function highlightitf(。lll21 

ia-r 

第兰步:,我们具体地来{l一看在网页 

中的操作过程。 

在这里用DIV标识来作多级滑动菜单 

列,用TABLE来做菜单项。要注意一f的 

是.这里的主菜单其实是一个表格,只是在 

【il'{t:ur2.filters.alpha.opacity<I o0) 

cur2.miters alpha、opacity+=20; 

else if(window highlighringj 

表格TD项中加人了诸如“,'lass=normal 

0nM0useDown:"this.ela*sNaIlIe= down ” ’’ 

elearlnterval(highlighling)} 

//拖动层的_s 

var OVel-=false,down=faIse.divleft,di- 

vtop; 

funI-tion/MOVe【1 

这娄的语句来达到美化效果。同时为了让 

子菜单项定位准确,我们把子菜单所在层都 

放在_r主菜单所在的层内。下图是通过 

dreamweaver体现出来的示意图,这样便能 

够更容易理解它了 

if(down) 

plane.style.1eft=event c:lientX—di— 

vleft;

top; 

plane.style.top event.clientY—div— 

J 

} 

//滑动层 

function bodyload() 

//定义主菜单列 

<div style=”position:absolute;z—in— 

dex:1;width:1:heisht:1;left:O:top:500 

ID plane onmousedown= down true;di— 

ifrplane.style.pixelTop!=O1 

vleft event clientX—parselnt 

(plane.style.1eft):divtop=event.ellentY— 

plane.style.pixelTop一=10 

parselnt(plane.style.top) 

down=faIse > 

onmouseup= 

setTimeout( bodyload() ,1) 

J 

//渐变显示层, 

function Show(divid) 

<table id="td 123 cellspacing 2 

width=100 13order=0 style= BORDER:# 

999999 I px solid; eurflor:

padding= 

<t 1) 

hand cell- 

bgeolor="#f4f4f4 

divid filters.revealTrans.apply(); 

divid.style.visibility= 'visible : 

<td hgcolor= #cccccc height="20 

style= BORDER:#999999 l Dx solid;cur- 

SOl':丌10ve,,) 

divid.filters.revealTrans.play(); 

j 

<div align:"ccrlter >多级滑动菜单 

</div> 

</td> 

(/tr> 

<tr> 

function Hide(divid) 

{ 

divid.filters.revealTrans.apply(); 

divid.style.visibility= hidden : 

divid.filters.revealTrans.play(); 

} 

<td cl鹅s:normal onMouseDown 

this.classN ̄l{le= down onMouseOver= 

——

谴 扣≯嗣嚏_ 19 

维普资讯

网络天地 

menu1 

NETWORK 

cursor:

f4r4f4 align= right ) 

<h1) 

l1H‘l 

hand eellpadding= .(1”bgcolor= 

this.className= up ,high(this), Show 

onMouseOut= this.elassName: 

normal .1ow(this),menu1.style.visibility= 

hidden style= filter:alpha(opac!ty=50) 

onMouseUp this.className= up > 

<td class normal onMouseDown= 

this className= down 

0nMouseOver 'his.elassName= up .t 

<div align= right >有下级菜单>> 

</djv) 

highfthis1 onMouseOut= this,className= 

</td> 

(/tr> 

<tr> 

normal .1ow(this) style= filter: alpha 

opacity=501 onMouseUp= 

this className= up > 

<td class normal onM 

thjs elassName down 

Down= 

<div Mign:”center >子菜单

</td> 

</div> 

onMouseOver= this.elassName up . 

</tr> 

<tr> 

high(this) Show(menu2)”onMouseOut= 

hits cla ̄ssName= normal 

ter: alpha ropacity=50、 

up ) 

,low(this), 

style= 'il—f 

<td class normal onMouseDown= 

this.className: down 

onMouseOver= this.className up . 

menu2.style.visibility= hidden 

onMouseUp= 

this elassName 

high(this1”onMouseOut= 'this.elassName= 

<div align= right >有下级菜单>) 

(/div> 

</td> 

(/tr> 

<tr> 

normal .1ow《this) style= 'iflter: alpha 

ropacity 50) onMouaeUp= 

this className= up > 

<div align:center>子菜单</div> 

</td> 

</tr> 

<tr> 

(【d class=noFnl ̄l onMouseDown= 

this.㈣la sName= down ” onMoHseOvet 

this.className= up ,high(this) onMouse— 

Out= this.elassName= normal .1ow(this) 

style= filter:alpha ropacity=50、 onMouse— 

<td class=normal onMouseDo,wn= 

this.className down 

this.className= up . onMouseOver 

Up= this.elassName= up > 

hlgh f this) onMouseOut= this.className= 

<div align= 'irght >无下级菜单>> 

</div> 

(/td> 

</tr> 

(/tatde> 

normal .1ow【this) style: 'filter: Mpha 

Iopacity 50、 'onMouseUp= 

this.className= up > 

<div align=center>子菜单

(/td> 

</tr> 

</div> 

//定义第一个子菜单列 

<div id= r1]enu1”style= position:ab— 

solute;top:24px;left:96px;z—index:1:vis— 

ihility:hidden:width:105 

onMouseOver=this style.visibility= 

visit】le 

</table> 

/div) 

定义第二个子菜单方法与定义第一个 

子菜单的方法完全相同,在此就不多说了 

关于多级滑动菜单的问题就讲到这儿 

了。由于本人水平有限,可能说得不太清楚, 

清各位多包涵。各位可以参考上述实例,编 

onMouseOut=this.style.visibility= 

hidden class tnenuv 

<table cellspacing=2 width=100 lmr— 

der=0 style= B0RDER:#999999 1 px solid; 

制自己的菜单了,希望这个例子能让你的主 

页更加吸引人! 释 

20 


本文标签: 菜单 定义 鼠标 效果 读者