用JavaScript实现网页“打字机”效果 |
|
http://www.sina.com.cn 2002/04/05 10:29 赛迪网 |
|
文/dogQ 在网页中经常有人使用swish来做打字效果,其实JavaScript也能做出那样的效果,按如下方法在HTML文件中加入JavaScript代码便可。要使用的文字你可以根据需要修改。
第一步:把如下代码加入<head>区域中 <SCRIPT LANGUAGE="JavaScript"> <!-- Original: Tarjei Davidsen (the@rescueteam.com) --> <!-- This script and many more are available free online at --> <!-- The JavaScript Source!! http://javascript.internet.com --> <!-- Begin var max=0; function textlist() { max=textlist.arguments.length; for (i=0; i<max; i++) this[i]=textlist.arguments[i]; } tl = new textlist( "用电脑拨打市话", "IE附带的NetMeeting软件,完全免费,可以进行PC到PC的网络通话, 可惜连接速度实在不敢恭维。", "另外IPhone可以直接拨到对方固定电话上面,连接速度也不赖, 惟一遗憾的就是只有14天的免费试用期。", "我在这里推荐MediaRing Talk中文版,", "可以免费同在线用户通话,而且缴纳少量费用就可以同固定电话连接。" ); var x = 0; pos = 0; var l = tl[0].length; function textticker() { document.tickform.tickfield.value = tl[x].substring(0, pos) + "_"; if(pos++ == l) { pos = 0; setTimeout("textticker()", 2000); if(++x == max) x = 0; l = tl[x].length; } else setTimeout("textticker()", 50); } // End --></script></head> |
第二步:把如下代码加入<body>区域中 <form name=tickform> <textarea name=tickfield rows=3 cols=38 style="background-color: rgb(0,0,0); color: rgb(255,255,255); cursor: default; font-family: Arial; font-size: 12px" wrap=virtual>The news will appear here when the page has finished loading.</textarea></form> |
第三步:把<body>改为 <body bgcolor="#fef4d9" OnLoad="textticker()"> |
|
|
|
|