一句一句話地顯示出來
有點類似於跑馬燈效果
文字效果的突出點比較明顯
推薦使用
制作方法
將下面的代碼復制到<body>~</body>裡
<script language=JavaScript
>
//設置下面的參數(寬度
高度和背景色)可以得到不同的顯示效果
var scrollerwidth=
var scrollerheight=
var scrollerbgcolor=
//下面的參數
不想使用背景圖的話設為空
var scrollerbackground=
//下面的參數設置顯示內容
可以使用HTML語法改變字體
大小和顏色及連接等
var messages=new Array()
messages[
]=
::::::::::::::::::::: 示例滾動新聞 :::::::::::::::::::::
messages[
]=
<a javascript:void(
)
>新奧特真三維虛擬演播室系統順利通過廣電總局檢測</a>
messages[
]=
<a javascript:void(
)
>新奧特參加
年江蘇廣播電視暨網絡設備展覽會成功 </a>
messages[
]=
<a javascript:void(
)
>九運組委會致函感謝新奧特提供電視字幕
為九運作出重要貢獻</a>
///////下面的代碼不要改變//////
if (messages
length>
)
i=
else
i=
function move
(whichlayer){
tlayer=eval(whichlayer)
if (tlayer
top>
&&tlayer
top<=
){
tlayer
top=
setTimeout(
move
(tlayer)
)
setTimeout(
move
(document
main
document
second)
)
return
}
if (tlayer
top>=tlayer
document
height*
){
tlayer
top
=
setTimeout(
move
(tlayer)
)
}
else{
tlayer
top=scrollerheight
tlayer
document
write(messages[i])
tlayer
document
close()
if (i==messages
length
)
i=
else
i++
}
}
function move
(whichlayer){
tlayer
=eval(whichlayer)
if (tlayer
top>
&&tlayer
top<=
){
tlayer
top=
setTimeout(
move
(tlayer
)
)
setTimeout(
move
(document
main
document
first)
)
return
}
if (tlayer
top>=tlayer
document
height*
){
tlayer
top
=
setTimeout(
move
(tlayer
)
)
}
else{
tlayer
top=scrollerheight
tlayer
document
write(messages[i])
tlayer
document
close()
if (i==messages
length
)
i=
else
i++
}
}
function move
(whichdiv){
tdiv=eval(whichdiv)
if (tdiv
style
pixelTop>
&&tdiv
style
pixelTop<=
){
tdiv
style
pixelTop=
setTimeout(
move
(tdiv)
)
setTimeout(
move
(second
)
)
return
}
if (tdiv
style
pixelTop>=tdiv
offsetHeight*
){
tdiv
style
pixelTop
=
setTimeout(
move
(tdiv)
)
}
else{
tdiv
style
pixelTop=scrollerheight
tdiv
innerHTML=messages[i]
if (i==messages
length
)
i=
else
i++
}
}
function move
(whichdiv){
tdiv
=eval(whichdiv)
if (tdiv
style
pixelTop>
&&tdiv
style
pixelTop<=
){
tdiv
style
pixelTop=
setTimeout(
move
(tdiv
)
)
setTimeout(
move
(first
)
)
return
}
if (tdiv
style
pixelTop>=tdiv
offsetHeight*
){
tdiv
style
pixelTop
=
setTimeout(
move
(second
)
)
}
else{
tdiv
style
pixelTop=scrollerheight
tdiv
innerHTML=messages[i]
if (i==messages
length
)
i=
else
i++
}
}
function startscroll(){
if (document
all){
move
(first
)
second
style
top=scrollerheight
second
style
visibility=
visible
}
else if (document
layers){
document
main
visibility=
show
move
(document
main
document
first)
document
main
document
second
top=scrollerheight+
document
main
document
second
visibility=
show
}
}
window
onload=startscroll
</script>
<ilayer id=main width=
&{ scrollerwidth};
height=
&{ scrollerheight};
bgcolor=
&{ scrollerbgcolor};
visibility=
hide
top=
>
<layer id=first width=
top=
left=
>
<script language=JavaScript
>
if (document
layers)
document
write(messages[
])
</script>
</layer>
<layer id=second width=
visibility=
hide
top=
left=
>
<script language=JavaScript
>
if (document
layers)
document
write(messages[
])
</script>
</layer>
</ilayer>
<script language=JavaScript
>
if (document
all){
document
writeln(
<span id=
main
>
)
document
writeln(
<div >
)
document
writeln(
<div id=
first
>
)
document
write(messages[
])
document
writeln(
</div>
)
document
writeln(
<div id=
second
>
)
document
write(messages[
])
document
writeln(
</div>
)
document
writeln(
</div>
)
document
writeln(
</span>
)
}
</script>
注意
在message[xxx]中不能含有空格
如下
messages[
]=
<table border=
><tr valign=top><td width=
>「
/
/
」</td><td width=
></td><td>服務器現在真的是怪怪的
剛剛還用了新的地址了
一會兒又變<br>成了現在的這個了
真是讓我干著急
真對不起大家啊!</td></tr></table>
正 確
messages[
]=
<table border=
><tr valign=top><td width=
>「
/
/
」</td>
<td width=
></td><td>服務器現在真的是怪怪的
剛剛還用了新的地址了
一會兒又變
<br>成了現在的這個了
真是讓我干著急
真對不起大家啊!</td></tr></table>
錯 誤
至此你就可以完成這個實例了
From:http://tw.wingwit.com/Article/program/Java/JSP/201311/19307.html