javascript|網頁
在網頁中經常有人使用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( "在此輸入要輸出的文字"); 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> |
第二步:把如下代碼加入<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" >
OK,大功告成!