让状态栏的文字动起来 |
|
让状态栏的文字动起来,不但能向用户提供一些有用的信息,而且增加的网页的动态效。下面是一些让状态栏文字动起来的JAVASCRIPT代码,共有三种效果,在使用时只需将相应的函数作为事件调用即可。更详细说明见我个人网站:http://bashan.oso.com.cn/
<script language=JavaScript> var MESSAGE="欢迎光临巴山电脑"//状态栏要显示的文字 var POSITION=100 var DELAY=5 var WID=10 var scrollID var direct=true var scroll=new statusMessageObject() function statusMessageObject(){ this.msg =MESSAGE this.out =" " this.pos =POSITION this.delay=DELAY this.i=0 this.reset=clearMessage this.srcoller1=scroller this.srcoller2=snapIn this.srcoller1=shake}//定义对象 function clearMessage(){//定义方法 this.pos=POSITION} function scroller(){//从右向左移动 for (scroll.i=0;scroll.i<scroll.pos;scroll.i++){ scroll.out += " "} if (scroll.pos >= 0) scroll.out += scroll.msg else scroll.out=scroll.msg.substring(-scroll.pos,scroll.msg.length) window.status=scroll.out scroll.out=" " scroll.pos-- if (scroll.pos < -(scroll.msg.length)) { scroll.reset()} scrollID=setTimeout('scroller()',scroll.delay)} function snapIn(jumpSpaces,position){//让字符从右向左堆放 var msg = scroll.msg var out = "" for(var i=0; i<position; i++) {out+= msg.charAt(i)} for(i=1;i<jumpSpaces;i++) {out += " "} out+=msg.charAt(position) window.status = out if(jumpSpaces <= 1) { position++ if(msg.charAt(position) == ' ') {position++ } jumpSpaces = 100-position } else if (jumpSpaces > 3) {jumpSpaces *= .75} else {jumpSpaces--}//实现先快后慢的效果 if(position != msg.length) { var cmd = "snapIn(" + jumpSpaces + "," + position + ")"; scrollID = window.setTimeout(cmd,scroll.delay); }else{ if (scroll.i < 1) {scroll.i+=1}else {window.status="" jumpSpaces=0 position=0 cmd = "snapIn(" + jumpSpaces + "," + position + ")"; scrollID = window.setTimeout(cmd,scroll.delay); } } function shake(WID){ //左右移动 scroll.out=""; for(scroll.i=0;scroll.i < WID;scroll.i++) {scroll.out += " "} scroll. out+=scroll.msg; window.status=scroll.out; if (WID <= 1) {direct=false } else { if (WID >= 10) {direct = true } } if (direct == true) {WID--} else {WID++} var cmd = "shake(" + WID + ")"; scrollID = window.setTimeout(cmd, DELAY); } </script> 说明:只要选上面的代码中的一个函数放在<head>与</head>之间,并加上函数调用就可以实现相应的效果。 |