示例演示:http://scboy.ik8.com/RandomRunHouse.htm
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<title>RandomRunHouse</title>
<script language="javascript">
msgArray = new Array(4);
msgArray[0] = "欢迎光临";
msgArray[1] = "白日依山静,黄河入海流";
msgArray[2] = "人道是,三国周郎赤壁";
msgArray[3] = "EmailTo: kof_he@163.com";
var msg = "";
var flag = true;
var addOne = 1;
var space = 50;
var addTwo = 0;
function randomMessage()
{
// 判断次句跑马灯是否跑完,跑完则重新随机获得语句
if ( flag == true )
{
// 随机获得状态栏显示语句
msg = msgArray[Math.floor( Math.random() * msgArray.length )];
// 表示跑马灯已开始,下次调用此函数则不在随机获得语句,直到跑马灯结束
flag = false;
}
if ( addOne < msg.length )
{
// 在状态栏中先一个字一个字递加的把msg字符串显示出来
window.status = msg.substring( 0, addOne );
addOne++;
}
else
{
var scroller = "";
// 添加状态栏前的空格
for ( i = 0; i < space; i++ )
{
scroller += " ";
}
scroller += msg;
window.status = scroller.substring( addTwo, space + msg.length );
addTwo++;
// 表示跑马灯结束,初始化数据
if ( addTwo > space + msg.length )
{
addOne = 0;
addTwo = 0;
flag = true;
}
}
setTimeout( 'randomMessage()', 100 );
}
</script>
</head>
<body onLoad="randomMessage();">
</body>
</html>
评论