Html实现滚动字幕效果

在 <body> 与 </body> 之间加入:

<TABLE BORDER="0" CELLSPACING="5" CELLPADDING="0" VSPACE="0" HSPACE="0" BORDERCOLOR="#B7B4B5">
<TR> <TD COLSPAN="2">
<!-DIRECTION=up/down/left/right/...>
<!-HEIGHT=字幕高度 WIDTH=字幕宽度>
<MARQUEE DIRECTION=up HEIGHT=150 WIDTH=100
ONMOUSEOUT=this.scrollDelay=1
ONMOUSEOVER=this.scrollDelay=600
SCROLLAMOUNT=1 SCROLLDELAY=1 CLASS="tt" >
滚动字幕效果<BR>
滚动字幕效果<BR>
滚动字幕效果<BR>
滚动字幕效果<BR>
滚动字幕效果<BR>
滚动字幕效果<BR>
滚动字幕效果<BR>
滚动字幕效果</MARQUEE>
</TD></TR> </TABLE>

一:将下面的代码放在〈HEAD〉与〈/HEAD〉之间
<style type="text/css">
<!--
.main {
font-family : Comic Sans Ms;
font-size : 13pt;
font-weight : bold;
}
-->
</style>
<script Language="Javascript">


bname=navigator.appName;
bversion=parseInt(navigator.appVersion)
if ((bname=="Netscape" && bversion>=4) || (bname=="Microsoft Internet Explorer" && bversion>=4)){
if (bname=="Netscape"){
brows=true
dt=1
}
else{
brows=false
dt=40
}
var z=0;
var msg=0;
var rgb=0;
var status=true;
var updwn=false;
var message= new Array();
var value=0;
var timer1;
var timer2;
var timer3;
var convert = new Array()
var hexbase= new Array("0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "A", "B", "C", "D", "E", "F");

// 修改下面的内容

var bgcolor="#FFFFFF"; //背景颜色
var color="#0000FF";  //字体颜色
message[0]='七色风欢迎你的光临!'
message[1]='有你的支持,我将不断进步'
message[2]='这里有很多JAVASCRIPT的例子'
message[3]='网址http://www.7wind.net'
message[4]='想成为高手,请常来坐坐!'
message[5]='如有问题请与我联系'
message[6]=''
message[7]=''

// Put here your own messages. Add as many as you wan't (Do not edit anything else in the Script except the lines above)

for (x=0; x<16; x++){
for (y=0; y<16; y++){
convert[value]= hexbase[x] + hexbase[y];
value++;
}
}

redx=color.substring(1,3);
greenx=color.substring(3,5);
bluex=color.substring(5,7);
hred=eval(parseInt(redx,16));
hgreen=eval(parseInt(greenx,16));
hblue=eval(parseInt(bluex,16));
eredx=bgcolor.substring(1,3);
egreenx=bgcolor.substring(3,5);
ebluex=bgcolor.substring(5,7);
ered=eval(parseInt(eredx,16));
egreen=eval(parseInt(egreenx,16));
eblue=eval(parseInt(ebluex,16));
red=ered;
green=egreen;
blue=eblue;

function start(){
if ((bname=="Netscape" && bversion>=4) || (bname=="Microsoft Internet Explorer" && bversion>=4)){
if (brows)
res=document.layers['textanim'].top
else
res=textanim.style.top
updwn=true;
timer1=window.setInterval('up()',dt)
}
}

function stop(){
if ((bname=="Netscape" && bversion>=4) || (bname=="Microsoft Internet Explorer" && bversion>=4)){
window.clearInterval(timer1);
window.clearInterval(timer2);
window.clearTimeout(timer3);
}
}

function breakf(){
if (status){
window.clearInterval(timer1);
window.clearInterval(timer2);
window.clearTimeout(timer3);
status=false
return;
}
else{
if (updwn)
timer1=window.setInterval('up()',dt)
else
timer2=window.setInterval('down()',dt)
status=true;
}
}


function up(){
if (red<hred){
if ((red+15)<hred){
red+=15;
redx = convert[red]
}
else{
red=hred
redx = convert[red]
}
}

if (red>hred){
if ((red-15)>hred){
red-=15;
redx = convert[red]
}
else{
red=hred
redx = convert[red]
}
}

if (green<hgreen){
if ((green+15)<hgreen){
green+=15;
greenx = convert[green]
}
else{
green=hgreen
greenx = convert[green]
}
}

if (green>hgreen){
if ((green-15)>hgreen){
green-=15;
greenx = convert[green]
}
else{
green=hgreen
greenx = convert[green]
}
}

if (blue<hblue){
if ((blue+15)<hblue){
blue+=15;
bluex = convert[blue]
}
else{
blue=hblue
bluex = convert[blue]
}
}

if (blue>hblue){
if ((blue-15)>hblue){
blue-=15;
bluex = convert[blue]
}
else{
blue=hblue
bluex = convert[blue]
}
}

rgb = "#"+redx+greenx+bluex;
if (brows){
document.layers['textanim'].document.linkColor=rgb;
document.layers['textanim'].document.vlinkColor=rgb;
document.layers['textanim'].document.writeln('<Pre><P Class="main" Align="Center"><font color="'+rgb+'">'+message[msg]+'</font></P></Pre>')
document.layers['textanim'].document.close();
}
else{
textanim.document.linkColor=rgb;
textanim.document.vlinkColor=rgb;
textanim.innerHTML='<Pre><P Class="main" Align="Center"><font color="'+rgb+'">'+message[msg]+'</font></P></Pre>'
}
if (z<19){
if (brows)
document.layers['textanim'].top-=2
else
textanim.style.posTop-=2
z++
}
else
{
updwn=false;
window.clearInterval(timer1);
timer2=window.setInterval('down()',dt)
}
}


function down(){
if (red<ered){
if ((red+15)<ered){
red+=15;
redx = convert[red]
}
else{
red=ered
redx = convert[red]
}
}

if (red>ered){
if ((red-15)>ered){
red-=15;
redx = convert[red]
}
else{
red=ered
redx = convert[red]
}
}

if (green<egreen){
if ((green+15)<egreen){
green+=15;
greenx = convert[green]
}
else{
green=egreen
greenx = convert[green]
}
}

if (green>egreen){
if ((green-15)>egreen){
green-=15;
greenx = convert[green]
}
else{
green=egreen
greenx = convert[green]
}
}

if (blue<eblue){
if ((blue+15)<eblue){
blue+=15;
bluex = convert[blue]
}
else{
blue=eblue
bluex = convert[blue]
}
}

if (blue>eblue){
if ((blue-15)>eblue){
blue-=15;
bluex = convert[blue]
}
else{
blue=eblue
bluex = convert[blue]
}
}

rgb = "#"+redx+greenx+bluex;
if (brows){
document.layers['textanim'].document.linkColor=rgb;
document.layers['textanim'].document.vlinkColor=rgb;
document.layers['textanim'].document.writeln('<Pre><P Class="main" Align="Center"><font color="'+rgb+'">'+message[msg]+'</font></P></Pre>')
document.layers['textanim'].document.close();
}
else{
textanim.document.linkColor=rgb;
textanim.document.vlinkColor=rgb;
textanim.innerHTML='<Pre><P Class="main" Align="Center"><font color="'+rgb+'">'+message[msg]+'</font></P></Pre>'
}
if (z<38){
if (brows)
document.layers['textanim'].top-=2
else
textanim.style.posTop-=2
z++
}
else
{
if (brows){
document.layers['textanim'].document.writeln('')
document.layers['textanim'].document.close();
}
else
textanim.innerHTML='';
window.clearInterval(timer2);
if(msg<message.length-1){
msg++;
z=0;
if (brows)
document.layers['textanim'].top=res;
else
textanim.style.top=res;
timer3=window.setTimeout('start()',100);
}
else
{
msg=0;
z=0;
if (brows)
document.layers['textanim'].top=res;
else
textanim.style.top=res;
timer3=window.setTimeout('start()',2000);
}
}
}
}


// done hiding -->
</script>
二:修改<body***>中的内容,将下面的代码加入原<body***>中
onLoad="start()" onUnload="stop()"

三:将下面的代码复制到〈BODY〉区
<div id="textanim" style="position: absolute; left: 10; top: 50" οnclick="breakf()"></div><Layer name="textanim" left="10" top="50"></Layer>

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值