本文實例講述了JS實作狀態列跑馬燈文字效果代碼。分享給大家參考,具體如下:
這款狀態列跑馬燈,文字跑動的定義在陣列內,自己可修改內容。現在的IE8似乎不相容,有缺失的程式碼,歡迎JS愛好者修正,修正請寄回一份。狀態列為效果顯示區。
運作效果截圖如下:
線上示範網址如下:
http://demo.jb51.net/js/2015/js-ztlpmd-txt-style-codes/
具體程式碼如下:
<HTML> <HEAD> <TITLE>间隔状态栏跑马灯</TITLE> <META http-equiv=Content-Type content="text/html; charset=gb2312"> <SCRIPT language=JavaScript> <!-- function scrollit(seed) { var m1 = "HI:你 好! "; var m2 = "欢迎访问脚本之家网站"; var m3 = "请 多 提 意 见,谢 谢!"; var m4 = "E-MAIL:"; var m5 = "/"; var msg=m1+m2+m3+m4+m5; var out = " "; var c = 1; if (seed > 100) { seed--; cmd="scrollit("+seed+")"; timerTwo=window.setTimeout(cmd,100); } else if (seed <= 100 && seed > 0) { for (c=0 ; c < seed ; c++) { out+=" "; } out+=msg; seed--; window.status=out; cmd="scrollit("+seed+")"; timerTwo=window.setTimeout(cmd,100); } else if (seed <= 0) { if (-seed < msg.length) { out+=msg.substring(-seed,msg.length); seed--; window.status=out; cmd="scrollit("+seed+")"; timerTwo=window.setTimeout(cmd,100); } else { window.status=" "; timerTwo=window.setTimeout("scrollit(100)",75); } } } //--> </SCRIPT> <META content="MSHTML 6.00.2900.2963" name=GENERATOR> </HEAD> <BODY bgColor=#fef4d9 onload=scrollit(100)> </BODY> </HTML>
希望本文所述對大家JavaScript程式設計有所幫助。