加入收藏 | 设为首页 | 会员中心 | 我要投稿 聊城站长网 (https://www.0635zz.com/)- 智能语音交互、行业智能、AI应用、云计算、5G!
当前位置: 首页 > 教程 > 正文

jquery单行文字向上滚动效果范例

发布时间:2023-10-25 14:50:17 所属栏目:教程 来源:
导读:代码如下:

<body>

<div id="title" style="width:100%;height:40px;">看看间断滚动文字</div>

<div id="content" class="infocontent">

<div id="top" class="infolist">
代码如下:
 
<body>
 
<div id="title" style="width:100%;height:40px;">看看间断滚动文字</div>
 
<div id="content" class="infocontent">
 
<div id="top" class="infolist">
 
<ul>
 
<li>央视315曝光: 华润深陷“海砂门”回应澄而未清</li>
 
<li>吉野家被曝餐具不消毒 波司登等羊绒衫不含羊绒</li>
 
<li>无锡警方公布“待产女警突发不幸”事发经过</li>
 
<li>中国人一天:最后的轮渡 视界:在家“搞定”</li>
 
</ul>
 
</div>
 
<div id="bottom" class="infolist"></div>
 
</div>
 
<div id="foot"></div>
 
</body>
 
代码如下:
 
.infolist{width:400px;matgin:0;}
 
.infolist ul{margin:0;padding:0;}
 
.infolist ul li{list-style:none;height:26px;line-height:26px;}
 
.infocontent{width:400px;height:26px;overflow:hidden;border:1px solid #666666;}
 
代码如下:
 
var interval=1000;//两次滚动之间的时间间隔
 
var stepsize=26;//滚动一次的长度,必须是行高的倍数,这样滚动的时候才不会断行
 
var objInterval=null;
 
$(document).ready( function(){
 
//用上部的内容填充下部
 
$("#bottom").html($("#top").html());
 
//给显示的区域绑定鼠标事件
 
$("#content").bind("mouseover",function(){StopScroll();});
 
$("#content").bind("mouseout",function(){StartScroll();});
 
//启动定时器
 
StartScroll();
 
});
 
//启动定时器,开始滚动
 
function StartScroll(){
 
objInterval=setInterval("verticalloop()",interval);
 
}
 
//清除定时器,停止滚动
 
function StopScroll(){
 
window.clearInterval(objInterval);
 
}
 
//控制滚动
 
function verticalloop(){
 
//判断是否上部内容全部移出显示区域
 
//如果是,从新开始;否则,继续向上移动
 
if($("#content").scrollTop()>=$("#top").outerHeight()){
 
$("#content").scrollTop($("#content").scrollTop()-$("#top").outerHeight());
 
}
 
//使用jquery创建滚动时的动画效果
 
$("#content").animate(
 
{"scrollTop" : $("#content").scrollTop()+stepsize +"px"},600,function(){
 
//这里用于显示滚动区域的scrollTop,实际应用中请删除
 
// $("#foot").html("scrollTop:"+$("#content").scrollTop());
 
});
 
}
 
 

(编辑:聊城站长网)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章