Jquery结合div+css实现文字间断停顿向上滚动效果

Javascript 1743 0 2012-08-06

Jquery结合div+css实现文字间断停顿向上滚动效果

<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>

上一篇:jquery each获取页面所有li标签内容描述

下一篇:iframe里面的页面调用父窗口,左右窗口js函数的方法

讨论数量:0

请先登录再发表讨论。 2024-04-24

天涯网魂
3 杠 5 星
TA 的文章
TA 的随言
TA 的资源链