JavaScript常用小技巧—文字从状态栏冒出

1 文字从状态栏右边冒出
 1 < html >
 2 < head >
 3      < title > 文字从状态栏右边冒出 </ title >
 4 </ head >
 5 < body >
 6  
 7 < script  language ="JavaScript" >  
 8<!-- 
 9function statusMessageObject(p,d) 
10  this.msg = MESSAGE 
11  this.out = " " 
12  this.pos = POSITION 
13  this.delay = DELAY 
14  this.i     = 0 
15  this.reset = clearMessage 
16}
 
17function clearMessage() 
18  this.pos = POSITION 
19}
 
20var POSITION = 100 
21var DELAY    = 4 
22 var MESSAGE  = "状态栏文字快速的一个一个弹出!!!    "  
23var scroll = new statusMessageObject() 
24function scroller() 
25  for (scroll.i = 0; scroll.i < scroll.pos; scroll.i++
26    scroll.out += " " 
27  }
 
28  if (scroll.pos >= 0
29   scroll.out += scroll.msg 
30  else scroll.out = scroll.msg.substring(-scroll.pos,scroll.msg.length) 
31  window.status = scroll.out 
32  scroll.out = " " 
33  scroll.pos-- 
34  if (scroll.pos < -(scroll.msg.length)) 
35   scroll.reset() 
36  }
 
37  setTimeout ("scroller()",scroll.delay) 
38}
 
39function snapIn(jumpSpaces,position) 
40  var msg = scroll.msg 
41  var out = "" 
42  for (var i=0; i<position; i++)  
43    {out += msg.charAt(i)} 
44  for (i=1;i<jumpSpaces;i++)  
45    {out += " "} 
46  out += msg.charAt(position) 
47  window.status = out 
48  if (jumpSpaces <= 1
49    position++ 
50    if (msg.charAt(position) == " ")  
51      {position++ } 
52    jumpSpaces = 100-position 
53  }
 else if (jumpSpaces >  3
54       {jumpSpaces *= .75} 
55  else 
56    {jumpSpaces--} 
57  if (position != msg.length) 
58    var cmd = "snapIn(" + jumpSpaces + "," + position + ")"
59    scrollID = window.setTimeout(cmd,scroll.delay); 
60  }
 else 
61    window.status="" 
62    jumpSpaces=0 
63    position=0 
64    cmd = "snapIn(" + jumpSpaces + "," + position + ")"
65    scrollID = window.setTimeout(cmd,scroll.delay); 
66    return false  
67  }
 
68  return true 
69}
 
70snapIn(100,0); 
71// --> 
72
</ script >   
73
74 </ body >
75 </ html >  

2 文字从状态栏左边冒出
 1 < html >
 2 < head >
 3      < title > 文字从状态栏左边冒出 </ title >
 4 </ head >
 5 < body >
 6  
 7 < script  language ="JavaScript" >  
 8var msg  = "状态栏文字从左一个一个冒出!!      " ; 
 9var interval = 120 
10var spacelen = 120
11var space10=" "
12var seq=0
13function Scroll() 
14len = msg.length; 
15window.status = msg.substring(0, seq+1); 
16seq++
17if ( seq >= len ) {  
18seq = 0;  
19window.status = ""
20window.setTimeout("Scroll();", interval ); 
21}
 
22else 
23window.setTimeout("Scroll();", interval ); 
24}
  
25Scroll(); 
26
</ script >  
27 </ body >
28 </ html >  

3 文字在状态栏逐字放入
 1 < html >
 2 < head >
 3      < title > 文字在状态栏逐字放入 </ title >
 4 </ head >
 5 < body >
 6  
 7 < script  language ="JavaScript" >  
 8<!-- 
 9function statusMessageObject(p,d) 
10  this.msg = MESSAGE 
11  this.out = " " 
12  this.pos = POSITION 
13  this.delay = DELAY 
14  this.i     = 0 
15  this.reset = clearMessage 
16}
 
17function clearMessage() 
18  this.pos = POSITION 
19}
 
20var POSITION = 100 
21var DELAY    = 4 
22 var MESSAGE  = "状态栏文字快速的一个一个弹出!!!    "  
23var scroll = new statusMessageObject() 
24function scroller() 
25  for (scroll.i = 0; scroll.i < scroll.pos; scroll.i++
26    scroll.out += " " 
27  }
 
28  if (scroll.pos >= 0
29   scroll.out += scroll.msg 
30  else scroll.out = scroll.msg.substring(-scroll.pos,scroll.msg.length) 
31  window.status = scroll.out 
32  scroll.out = " " 
33  scroll.pos-- 
34  if (scroll.pos < -(scroll.msg.length)) 
35   scroll.reset() 
36  }
 
37  setTimeout ("scroller()",scroll.delay) 
38}
 
39function snapIn(jumpSpaces,position) 
40  var msg = scroll.msg 
41  var out = "" 
42  for (var i=0; i<position; i++)  
43    {out += msg.charAt(i)} 
44  for (i=1;i<jumpSpaces;i++)  
45    {out += " "} 
46  out += msg.charAt(position) 
47  window.status = out 
48  if (jumpSpaces <= 1
49    position++ 
50    if (msg.charAt(position) == " ")  
51      {position++ } 
52    jumpSpaces = 100-position 
53  }
 else if (jumpSpaces >  3
54       {jumpSpaces *= .75} 
55  else 
56    {jumpSpaces--} 
57  if (position != msg.length) 
58    var cmd = "snapIn(" + jumpSpaces + "," + position + ")"
59    scrollID = window.setTimeout(cmd,scroll.delay); 
60  }
 else 
61    window.status="" 
62    jumpSpaces=0 
63    position=0 
64    cmd = "snapIn(" + jumpSpaces + "," + position + ")"
65    scrollID = window.setTimeout(cmd,scroll.delay); 
66    return false  
67  }
 
68  return true 
69}
 
70snapIn(100,0); 
71// --> 
72
</ script >   
73
74 </ body >
75 </ html >  
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值