Display a dynamic Ticker tape. The content can be read from a database. The speed, background color, font, width and height can be customized. This project is divided into 2 parts:
1) Include File: Ticker Tape Code (TickerInclude.asp) 2) Main file: the file you want to put the Ticker tape into.
Here is the code:
TickerInclude.asp
<% 'Created by Max Cappellari 'to get the content from a Database: 'simply create a Recordset object here. Link1 = "<a href='http://www.yahoo.com'>http://www.yahoo.com</a>" Link2 = "<a href='http://www.cnn.com'>http://www.cnn.com</a>" Link3 = "<a href='http://www.aol.com'>http://www.aol.com</a>" 'Settings TickerColor = "#9CD3FF" TickerHeight = 15 TickerWidth = 300 %>
<style> <!-- #tickertape { position:relative; layer-background-color:<%=TickerColor%>; width:<%=Tickerwidth%>; height:<%=TickerHeight%>; }
#subtickertape{ background-color:<%=TickerColor%>; position:absolute; border: 0px <%=TickerColor%> width:<%=Tickerwidth%>; height:<%=TickerHeight%>; }
.subtickertapefont { font: 12px underlined Verdana; text-decoration:none; color:black; }
.subtickertapefont a { color:black; text-decoration:none; } --> </style>
<script language="JavaScript">
function regenerate() { window.location.reload()
}
function regenerate2() { if (document.layers) setTimeout("window.onresize = regenerate",450) }
function update() { if (document.layers){ document.tickertape.document.subtickertape.document.write ('<span class="subtickertapefont">'+news[i]+'</span>') document.tickertape.document.subtickertape.document.close() } else { document.all.subtickertape.innerHTML=news[i] } if (i<news.length-1) i++ else i=0 setTimeout("update()",speed) }
</script> <%' To get the content from a database, Loop through the recordset here %>
<form name="tform" id="tform"> <input type=hidden name="link1" value="<%=Link1%>"> <input type=hidden name="link2" value="<%=Link2%>"> <input type=hidden name="link3" value="<%=Link3%>"> </form>
<% 'end of loop %>
<script language="Javascript"> //default speed is 4.5 seconds var speed = 4500
var news = new Array()
news[0] = document.forms["tform"].item("link1").value news[1] = document.forms["tform"].item("link2").value news[2] = document.forms["tform"].item("link3").value
i = 0
</script>
<table border=0 bgcolor="<%=TickerColor%>" cellpadding=0 cellspacing=0 width=<%=TickerWidth%>> <tr bgcolor="<%=TickerColor%>" height=<%=TickerHeight%>> <td bgcolor="<%=TickerColor%>"> <div id="tickertape"> <div id="subtickertape" class="subtickertapefont">Initializing...</div> </div> </td> </tr> </table>
<!-- end of file-->
Then in the Main file just add the following in the <BODY> Tag:
<BODY Onload = "if (document.all||document.layers){regenerate2();update()}">
<!--#include File="TickerInclude.asp"-->
That's it!
|