home > real world > web resource > web source codes >
This DHTML script will cycle through several different text links.
STEP 1/2: Copy this code into the <HEAD> of your HTML document:
<HEAD>
<style>
<!--
#msgline {
position:relative;
width:400;
height:20;
}
#msgtext {
position:absolute;
border: 1px solid #009900;
padding:3px;
width:400;
height:20;
}
.msgtextfont {
font:bold 12px Trebuchet MS;
position:absolute;
left:5px;
}
.msgtextfont a {color:#9999ff;}
-->
</style>
</HEAD>
STEP 2/2: Put this code in the <BODY> of your document:
<BODY onload="if (document.all||document.layers) {regenerate2();update()}">
<div id="msgline">
<div id="msgtext" class="msgtextfont">Starting Messages...</div>
</div>
<script language="JavaScript1.2">
var speed=3000
var news=new Array()
news[0]="<a href='link1'>First line of text...</a>"
news[1]="<a href='link2'>Second line of text...</a>"
news[2]="<a href='link3'>Third line of text...</a>"
news[3]="<a href='link4'>Add as many as you want...</a>"
i=0
if (document.all)
tickerobject=document.all.msgtext.style
else
tickerobject=document.msgline.document
function regenerate(){
window.location.reload()
}
function regenerate2(){
if (document.layers)
setTimeout("window.onresize=regenerate",450)
}
function update(){
BgFade(0xff,0xff,0xff, 0x22,0x66,0x22,15);
if (document.layers){
document.msgline.document.msgtext.document.write('<span class="msgtextfont">'+news[i]+'</span>')
document.msgline.document.msgtext.document.close()
}
else
document.all.msgtext.innerHTML=news[i]
if (i<news.length-1)
i++
else
i=0
setTimeout("update()",speed)
}
function BgFade(red1, grn1, blu1, red2,
grn2, blu2, steps) {
sred = red1; sgrn = grn1; sblu = blu1;
ered = red2; egrn = grn2; eblu = blu2;
inc = steps;
step = 0;
MsgDither();
}
function MsgDither() {
var epct = step/inc;
var spct = 1 - epct;
if (document.layers)
tickerobject.bgColor =
Math.floor(sred * spct + ered *
epct)*256*256 +
Math.floor(sgrn * spct + egrn * epct)*256 +
Math.floor(sblu * spct + eblu * epct);
else
tickerobject.backgroundColor=
Math.floor(sred * spct + ered *
epct)*256*256 +
Math.floor(sgrn * spct + egrn * epct)*256 +
Math.floor(sblu * spct + eblu * epct);
if ( step < inc ) {
setTimeout('MsgDither()',50);
}
step++;
}
</script>
</BODY>
|