跑马灯

<html  >
<head>
<title>setTimerOut</title>
<meta />

</head>
<body  >
<div id="container" style="overflow:hidden;height:60px ;cursor:pointer;border:1px solid red" onmouseover="stopSetTimeOut();" onmouseout="startSetTimeOut();">
<div id="reMsg"  >style="border:1px solid blue"</div>
<div id="joinMsg"   >style="border:1px solid yellow"</div>
</div>
</body>
</html>
<script>var v_setTimeOut=null;
var i=0,j=0,k=0,m=0,n=0;
var container= document.getElementById("container");
var joinMsg= document.getElementById("joinMsg");
var reMsg= document.getElementById("reMsg");
function getMsg(){
	reMsg.innerHTML ="<span title='请求数据库"+(++i)+"'>请求数据库"+(i)+"</span>";
	reMsg.innerHTML +="<br><span title='请求数据库"+(++j)+"'>测试数据"+(j)+"</span>";
	reMsg.innerHTML +="<br><span title='请求数据库"+(++k)+"'>您好,太平洋服务小姐"+(k)+"</span>";
	reMsg.innerHTML +="<br><span title='请求数据库"+(++m)+"'>理赔满意回访"+(m)+"</span>";
	reMsg.innerHTML +="<br><span title='请求数据库"+(++n)+"'>什么什么的"+(n)+"</span>";
	joinMsg.innerText=reMsg.innerText;
	stopSetTimeOut();
	setTimeout("getMsg()",5000);
	//container.scrollTop=0;
	showMsg();
}
getMsg();
//demo2.innerText=demo1.innerText
function showMsg(){
	if (container.offsetHeight < reMsg.offsetHeight)
	{
		   if(joinMsg.offsetTop-container.scrollTop<=0){
				container.scrollTop-=reMsg.offsetHeight
			}else{
				container.scrollTop++;
			}
			startSetTimeOut();
	}else{
		joinMsg.innerText="";
	}
}
function startSetTimeOut(){
		v_setTimeOut = setTimeout("showMsg()",200);
}
function stopSetTimeOut(){
	clearTimeout(v_setTimeOut);
}
</script>

你可能感兴趣的:(settimeout)