JS实现打字效果(我的公告栏就是用这个实现的)

复古JavaScript打字效果
本文介绍了一个使用纯JavaScript实现的动态打字效果案例,通过逐字符显示文本的方式增强页面交互感。该效果能够处理HTML标签,并支持不同颜色的文本显示。
 1None.gif<script language=javascript>
 2None.gifvar layers =document.layers,style=document.all,both=layers||style,idme=908601;
 3ExpandedBlockStart.gifContractedBlock.gifif(layers)dot.gif{layerRef='document.layers';styleRef ='';}if(style)dot.gif{layerRef='document.all';styleRef = 
 4ExpandedBlockEnd.gif'.style';}

 5ExpandedBlockStart.gifContractedBlock.giffunction writeOnText(obj,str)dot.gif{
 6ExpandedSubBlockStart.gifContractedSubBlock.gifif(layers)with(document[obj])dot.gif{ document.open();document.write(str);document.close();}
 7ExpandedBlockEnd.gifif(style)eval(obj+'.innerHTML=str');   }

 8None.gifvar dispStr=new Array("从小父母就教育我要诚实,所以我必须承认我长得很帅。但是孔老夫子说过,以貌取人是不对的,所以你千万不要因为我长得帅而喜欢我。<br><br>葡萄美酒夜光杯,欲饮琵琶马上催。醉卧沙场君莫笑,古来征战几人回!<br><br>红尘过客,几度相思,几曲闲愁dot.gif..我为谁思? 苍茫尘世,几许伤悲,几多忧愁dot.gif..我为谁累?");
 9None.gifvar overMe=0;
10ExpandedBlockStart.gifContractedBlock.giffunction txtTyper(str,idx,idObj,spObj,clr1,clr2,delay,plysnd)dot.gif{
11InBlock.gifvar tmp0=tmp1= '',skip=100;
12ExpandedSubBlockStart.gifContractedSubBlock.gifif (both && idx<=str.length) dot.gif{
13ExpandedSubBlockStart.gifContractedSubBlock.gifif (str.charAt(idx)=='<')dot.gifwhile(str.charAt(idx)!='>') idx++;idx++;}
14ExpandedSubBlockStart.gifContractedSubBlock.gifif (str.charAt(idx)=='&'&&str.charAt(idx+1)!=' ')dot.gifwhile (str.charAt(idx)!= ';')idx++;idx++;}
15InBlock.giftmp0 = str.slice(0,idx);
16InBlock.giftmp1 = str.charAt(idx++);
17ExpandedSubBlockStart.gifContractedSubBlock.gifif (overMe==0 && plysnd==1)dot.gif{
18ExpandedSubBlockStart.gifContractedSubBlock.gifif (navigator.plugins[0])dot.gif{
19ExpandedSubBlockStart.gifContractedSubBlock.gifif(navigator.plugins["LiveAudio"][0].type=="audio/basic" && navigator.javaEnabled())dot.gif{document.embeds
20InBlock.gif[0].stop();
21ExpandedSubBlockEnd.gifsetTimeout("document.embeds[0].play(false)",100);}

22ExpandedSubBlockStart.gifContractedSubBlock.gif}
 else if (document.all)dot.gif{
23InBlock.gifding.Stop();
24ExpandedSubBlockEnd.gifsetTimeout("ding.Run()",100);}

25ExpandedSubBlockEnd.gifoverMe=1;}
else overMe=0;
26InBlock.gifwriteOnText(idObj, "<span class="+spObj+"><font color='"+clr1+"'>"+tmp0+"</font><font color='"+clr2
27InBlock.gif+"'>"+tmp1+"</font></span>");
28ExpandedBlockEnd.gifsetTimeout("txtTyper('"+str+"', "+idx+", '"+idObj+"', '"+spObj+"', '"+clr1+"', '"+clr2+"', "+delay+" ,"+plysnd+")",delay);}
}

29ExpandedBlockStart.gifContractedBlock.giffunction init()dot.gif{txtTyper(dispStr[0], 0, 'ttl0', 'ttl1', 'red', '#99FF33', 3000);}
30None.gif</script>
31None.gif<DIV class=ttl1 id=ttl0></DIV>
32None.gif<body bgcolor="#fef4d9" onload=init()>

转载于:https://www.cnblogs.com/cnzhouhai/archive/2007/08/16/858886.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值