<script type="text/javascript" src="script/jquery-1.7.2.min.js"></script>
<script type="text/javascript">
var interval=3000;//两次滚动之间的时间间隔
var stepsize=14;//记得这里要与样式里写的高一样,要不循环起来会错位
var scrollspeed="normal";//可选("slow", "normal", or "fast"),或者滚动动画时长的毫秒数
var objInterval=null;
$(document).ready(function(){
//给显示的区域绑定鼠标事件
$("#content").bind("mouseover",function(){StopScroll();});
$("#content").bind("mouseout",function(){StartScroll();});
//启动定时器
StartScroll();
});
//启动定时器,开始滚动
function StartScroll(){
objInterval=setInterval("verticalloop()",interval);
}
//清除定时器,停止滚动
function StopScroll(){
window.clearInterval(objInterval);
}
//控制滚动
function verticalloop(){
//使用jquery创建滚动时的动画效果
$("#content").animate({"scrollTop" : $("#content").scrollTop()+stepsize +"px"},scrollspeed,function(){
//这里用于显示滚动区域的scrollTop,实际应用中请删除
$("#foot").html("scrollTop:"+$("#content").scrollTop());
//判断是否上部内容全部移出显示区域,如果是,从新开始;否则,继续向上移动
if(($("#content").scrollTop()+stepsize)>=$("#top").outerHeight()){
$("#content").scrollTop($("#content").scrollTop()-$("#top").outerHeight());
}
});
}
</script>
style:
.infolist{width:400px;matgin:0;}
.infolist ul li{list-style:none;height:14px; font-size:12px;}
.infocontent{width:400px;height:14px;overflow:hidden}
HTML:
<div id="content" class="infocontent">
<div id="top" class="infolist">
<ul>
<li>全国政协首次公布去年会议花销 共5900万 1</li>
<li>全国政协首次公布去年会议花销 共5900万 2</li>
<li>全国政协首次公布去年会议花销 共5900万 3</li>
<li>全国政协首次公布去年会议花销 共5900万 4</li>
<li>全国政协首次公布去年会议花销 共5900万 5</li>
<li>全国政协首次公布去年会议花销 共5900万 6</li>
<li>全国政协首次公布去年会议花销 共5900万 7</li>
<li>全国政协首次公布去年会议花销 共5900万 8</li>
<li>全国政协首次公布去年会议花销 共5900万 9</li>
<li>全国政协首次公布去年会议花销 共5900万 10</li>
<li></li> <!-- 这里为多加一条空的,让其继续循环 -->
</ul>
</div></div>
<div id="foot"></div>