日期:2014-05-16  浏览次数:20436 次

JavaScript实现消息动态循环
<html>

<head>

<title></title>
<link rel="stylesheet" type="text/css" href="placard.css">
</head>

<body>
<div class="ct_BAB" align = "center">
	<div class="ct_BABA">
		<div class="ct_BABAA">
				<div class="ct_BABABAA"></div>
				<div class="ct_BABABAB">
					我的博客文章
				</div>
		</div>
		<div class="ct_BABAB"> 
			<div id="placardContent" class="ct_BABABB">								
			</div>
			<div id="placardTemp" style="display:none;">
				<div id="0placardItem" >
					<a target="_blank" href="#">1. hibernate返回一个实际的类型安全java对象时遇到的错误</a><br>
				</div>
				<div id="1placardItem" >
					<a target="_blank" href="#">2. java 日期处理</a><br>
				</div>
				<div id="2placardItem" >
					<a target="_blank" href="#">3. linux挂载windows上的共享文件</a><br>
				</div>
				<div id="3placardItem" >
					<a target="_blank" href="#">4. 执行hql参数多余错误</a><br>
				</div>
				<div id="4placardItem" >
					<a target="_blank" href="#">5. JQUERY对页面属性的选择控制(整理)</a><br>
				</div>
				<div id="5placardItem" >
					<a target="_blank" href="#">6. Lucene相关资料</a><br>
				</div>
				<div id="6placardItem" >
					<a target="_blank" href="#">7. 自己写了个Hessian</a><br>
				</div>
		</div>
		<script type="text/javascript">
			var placartItemCount = new Number(0);//公告总数
			placartItemCount = document.getElementById("placardTemp").getElementsByTagName("a").length;
			var currentIndex = new Number(0);//当前的第一条公告位置
			var displayCount = new Number(3);//定义公告显示个数
			/**
			*	动态滚动公告信息
			**/
			function placardDisplay(){
				if(currentIndex == placartItemCount)
					currentIndex = 0;
					
				var str = "";
				var marignCount = placartItemCount-currentIndex;
				
				for(var i = currentIndex; i < placartItemCount; i++){
					var id = i + "placardItem";
					str += document.getElementById(id).innerHTML;
					if((i - currentIndex) == (displayCount-1))	
						break;									 									 
				}	
				
				if(marignCount < displayCount){
					for(var j = 0; j < (displayCount - marignCount); j++){
				 		id = j + "placardItem";
				 		str += document.getElementById(id).innerHTML;	
				 	}
				 }
				document.getElementById("placardContent").innerHTML = str;	
				currentIndex++;				    
			}  	
			
			placardDisplay();
			
			if(placartItemCount > displayCount)						  
				setInterval(placardDisplay,3000); //每三秒执行一次
		</script>
	</div>
	<div class="ct_BABAC"></div>
</div>
</body>

</html>

1 楼 lym6520 2009-04-23  
对a标签加入事件:
onmouseover="clearTimeout(iTimeoutId);"
onmouseout="iTimeoutId = setInterval(placardDisplay,3000);"

修改:setInterval(placardDisplay,3000); //每三秒执行一次
为:
var iTimeoutId = setInterval(placardDisplay,3000); //每三秒执行一次

当鼠标移到文字上方时停留,移开时开始循环。
2 楼 lym6520 2009-04-28  
bug修改:增加条件

if(marignCount < displayCount){  
                    for(var j = 0; j < (displayCount - marignCount); j++){  
                        id = j + "placardItem";  
                        str += document.getElementById(id).innerHTML;&nb