|           编程(Programming)是编定程序的中文简称,就是让计算机代码解决某个问题,对某个计算体系规定一定的运算方式,使计算体系按照该计算方式运行,并最终得到相应结果的过程。为了使计算机能够理解(understand)人的意图,人类就必须将需解决的问题的思路、方法和手段通过计算机能够理解的形式告诉计算机,使得计算机能够根据人的指令一步一步去工作,完成某种特定的任务。这种人和计算体系之间交流的过程就是编程。 【实例名称】 JS代码实现幻灯片式的导航菜单 【实例描述】 导航菜单用一个div封装,每次只显示一个菜单,并实现菜单变化时的幻灯片效果。 【实例代码】   <html xmlns="http://www.w3.org/1999/xhtml" >
<head>
<title>标题页-本站(www.xue51.com)</title>
<style>
#linkView{
position:relative;
layer-background-color:black;
width:400;
height:12;
; font-family: "宋体"; font-size: 9pt}
#subtickertape{
background-color:black;
position:absolute;
border: 1px solid black;
width:400;
height:12;
; font-family: "宋体"; font-size: 9pt
}
.subtickertapefont{
font:bold 9pt "宋体";
text-decoration:none;
color:white;
}
.subtickertapefont a{
color:white;
text-decoration:none;
; font-family: "宋体"; font-size: 9pt}
</style>
</head>
<body bgcolor="#fef4d9" onload="if 
(document.all||document.layers) {regenerate2();update()}">
<div id="linkView"> 
<div id="subtickertape" class="subtickertapefont">初始化...</div>
</div>
<script language="JavaScript">
//默认速度3秒,可以修改速度快慢。
var speed=3000
var news=new Array()
news[0]="<a href='index1.htm'>我的连接1</a>"//创建链接树数组
news[1]="<a href='index2.htm'>我的连接2</a>"
news[2]="<a href='index3.htm'>我的连接3</a>"
news[3]="<a href='index4.htm'>我的连接4</a>"
news[4]="<a href='index5.htm'>我的连接5</a>"
news[5]="<a href='index6.htm'>我的连接6</a>"
news[6]="<a href='index7.htm'>我的连接7</a>" //显示的信息内容按照格式添加。
i=0
if (document.all)
tickerobject=document.all.subtickertape.style
else
tickerobject=document.linkView.document
function regenerate(){
window.location.reload()        
//重新加载页面
}
function regenerate2(){
if (document.layers)           
//非IE浏览器时的定时器
setTimeout("window.onresize=regenerate",450)
} function update(){
 BgFade(0xff,0xff,0xff, 0x00,0x00,0x00,10);
if (document.layers){
document.linkView.document.subtickertape.document.write
('<span class="subtickertapefont">'+news[i]+'</span>')
document.linkView.document.subtickertape.document.close()
}
else 
document.all.subtickertape.innerHTML=news[i]
//动态显示链接(使用数组索引找到要显示的链接)
if (i<news.length-1)
//      判断是否已经显示完所有链接
i++                                         
//如果不是,则显示下个链接
else
i=0              //否则从头开始
setTimeout("update()",speed)
}  function BgFade(red1, grn1, blu1, red2,
 grn2, blu2, steps) {
 sred = red1; sgrn = grn1; sblu = blu1;
//颜色的设置
 ered = red2; egrn = grn2; eblu = blu2; 
 inc = steps; 
 step = 0; 
 RunFader();
 }
 function RunFader() {
 var epct = step/inc; 
 var spct = 1 - epct; 
 if (document.layers)
 tickerobject.bgColor =
 Math.floor(sred * spct + ered *
 epct)*256*256 +
 Math.floor(sgrn * spct + egrn * epct)*256 +
 Math.floor(sblu * spct + eblu * epct); 
 else                             
 //背景色的渐变效果,注意颜色的设置
 tickerobject.backgroundColor=
 Math.floor(sred * spct + ered *
 epct)*256*256 +
 Math.floor(sgrn * spct + egrn * epct)*256 +
 Math.floor(sblu * spct + eblu * epct); 
 if ( step < inc ) {
 setTimeout('RunFader()',50);   
//循环执行渐变效果
 }
 step++;
 }
</script>
</body>
</html>
 
 【运行效果】   【难点剖析】 本例的重点是链接的显示和特效的实现。所有链接都保存在“news”数组中。通过循环使用数组索引逐个显示链接的内容,然后使用“RunFader”方法,实现链接更改时的幻灯片效果。 【源码下载】 为了JS代码的准确性,请点击:幻灯片式的导航菜单 进行本实例源码下载  
 使用编程语言写的程序,由于每条指令都对应计算机一个特定的基本动作,所以程序占用内存少、执行效率高。 
 |