效果如图:
源代码如下,同时在同一个文件夹下放一个js文件(jquery-1.3.2.js):
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>一页多个滚动区</title>
<script type="text/javascript" src="jquery-1.3.2.js"></script>
<style type="text/css">
<!--
body{
background-color:#0D6B2D;margin-top:20px;
color:#000;
font:12px/22px "宋体";
line-height:18px;
text-align:left;
}
.div1,.div2{
float:left;margin:20px;width:200px;height:18px;line-height:18px;overflow:hidden;
background-color:#FFFF00;
}
#RunTopic1,#RunTopic2{
clear:both;width:200px;height:18px;line-height:18px;overflow:hidden;
background-color:#FFFF00;
}
/* 超链接 */
A:link {
COLOR: #005534; TEXT-DECORATION: none
}
A:visited {
COLOR: #005534; TEXT-DECORATION: none
}
A:hover {
COLOR: #FF0000; TEXT-DECORATION: none
}
A:active {
COLOR: #bc2931
}
-->
</style>
</head>
<body>
<div >http://wmnmtm.blog.163.com</div>
<div class="div1">
<ul id="RunTopic1">
<li>文字1</li>
<li>文字2</li>
<li>文字3</li>
<li>文字4</li>
<li>文字5</li>
</ul>
</div>
<div class="div2">
<ul id="RunTopic2">
<li>文字1</li>
<li>文字2</li>
<li>文字3</li>
<li>文字4</li>
<li>文字5</li>
</ul>
</div>
</body>
<script type="text/javascript">
$(document.body).ready(function(){
$("#RunTopic1").RollTitle({line:1,speed:200,timespan:1500});
$("#RunTopic2").RollTitle({line:1,speed:200,timespan:1500});
});
</script>
</html>
<!--
调用方法:
line:一次卷动的文本行数
speed:卷动动画的时间
timespan:间隔时间
-->
<script>
(function($){
$.fn.extend({
RollTitle: function(opt,callback){
if(!opt) var opt={};
var _this = this;
_this.timer = null;
_this.lineH = _this.find("li:first").height();
_this.line=opt.line?parseInt(opt.line,15):parseInt(_this.height()/_this.lineH,10);
_this.speed=opt.speed?parseInt(opt.speed,10):3000, //卷动速度,数值越大,速度越慢(毫秒
_this.timespan=opt.timespan?parseInt(opt.timespan,13):5000; //滚动的时间间隔(毫秒
if(_this.line==0) this.line=1;
_this.upHeight=0-_this.line*_this.lineH;
_this.scrollUp=function(){
_this.animate({
marginTop:_this.upHeight
},_this.speed,function(){
for(i=1;i<=_this.line;i++){
_this.find("li:first").appendTo(_this);
}
_this.css({marginTop:0});
});
}
_this.hover(function(){
clearInterval(_this.timer);
},function(){
_this.timer=setInterval(function(){_this.scrollUp();},_this.timespan);
}).mouseout();
}
})
})(jQuery);
</script>
以上代码本人做过些改动,经测试完全可用,效果很好,也不存在滚动着出现错位的现象。