当前位置:阳诡子 > 建站 > 正文

JQ纵向文字翻滚

时间:2021-03-05  来源:  作者:

前言

纵向文字翻滚,有单行和多行!

代码

<!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" lang="utf-8">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<script src="http://lib.sinaapp.com/js/jquery/1.5/jquery.min.js" type="text/javascript"></script>
<title>上下文字翻滚</title>
<style type="text/css">
#demo h2{background:#a40000; font-size:12px; color:#fff; font-weight:normal; text-align:center; width:100px; height:25px;line-height:25px; margin:30px 0 0 20px}
#demo ul.line,#demo ul.mulitline{width:500px; height:30px; background:#eee; overflow:hidden;margin-bottom:20px;border:2px solid #a40000}
#demo ul.mulitline{height:90px}
#demo li{height:30px;text-indent:15px; font-size:12px; line-height:30px;list-style:none}
</style>
<script type="text/javascript">
$(function(){
//单行应用@Mr.Think
var _wrap=$('ul.line');//定义滚动区域
var _interval=2000;//定义滚动间隙时间
var _moving;//需要清除的动画
_wrap.hover(function(){
clearInterval(_moving);
//当鼠标在滚动区域中时,停止滚动
},function(){
_moving=setInterval(function(){
var _field=_wrap.find('li:first');
//此变量不可放置于函数起始处,li:first取值是变化的
var _h=_field.height();//取得每次滚动高度
_field.animate({marginTop:-_h+'px'},600,function(){
//通过取负margin值,隐藏第一行
_field.css('marginTop',0).appendTo(_wrap);
//隐藏后,将该行的margin值置零,并插入到最后,实现无缝滚动
})
},_interval)//滚动间隔时间取决于_interval
}).trigger('mouseleave');
//函数载入时,模拟执行mouseleave,即自动滚动
});
$(function(){
//多行应用@Mr.Think
var _wrap=$('ul.mulitline');//定义滚动区域
var _interval=3000;//定义滚动间隙时间
var _moving;//需要清除的动画
_wrap.hover(function(){
clearInterval(_moving);
//当鼠标在滚动区域中时,停止滚动
},function(){
_moving=setInterval(function(){
var _field=_wrap.find('li:first');
//此变量不可放置于函数起始处,li:first取值是变化的
var _h=_field.height();//取得每次滚动高度
_field.animate({marginTop:-_h+'px'},600,function(){
//通过取负margin值,隐藏第一行
_field.css('marginTop',0).appendTo(_wrap);
//隐藏后,将该行的margin值置零,并插入到最后,实现无缝滚动
})
},_interval)//滚动间隔时间取决于_interval
}).trigger('mouseleave');
//函数载入时,模拟执行mouseleave,即自动滚动
});
</script>
</head>
<body>
<div id="demo">
<h2>单行应用</h2>
<ul class="line">
<li><a title="测试文本测试文本" href="1.html">测试文本测试文本</a> 20xx年xx月xx日 (6)</li>
<li><a title="测试文本测试文本" href="1.html">测试文本测试文本</a> 20xx年xx月xx日 (6)</li>
<li><a title="测试文本测试文本" href="1.html">测试文本测试文本</a> 20xx年xx月xx日 (6)</li>
<li><a title="测试文本测试文本" href="1.html">测试文本测试文本</a> 20xx年xx月xx日 (6)</li>
<li><a title="测试文本测试文本" href="1.html">测试文本测试文本</a> 20xx年xx月xx日 (6)</li>
</ul>
<!--//jQ版本//-->
<h2>多行应用</h2>
<ul class="mulitline">
<li><a title="测试文本测试文本" href="1.html">测试文本测试文本</a> 20xx年xx月xx日 (6)</li>
<li><a title="测试文本测试文本" href="1.html">测试文本测试文本</a> 20xx年xx月xx日 (6)</li>
<li><a title="测试文本测试文本" href="1.html">测试文本测试文本</a> 20xx年xx月xx日 (6)</li>
<li><a title="测试文本测试文本" href="1.html">测试文本测试文本</a> 20xx年xx月xx日 (6)</li>
<li><a title="测试文本测试文本" href="1.html">测试文本测试文本</a> 20xx年xx月xx日 (6)</li>
<li><a title="测试文本测试文本" href="1.html">测试文本测试文本</a> 20xx年xx月xx日 (6)</li>
</ul>
<!--//多行应用//-->
</div>
</body>
</html>
来顶一下
返回首页
返回首页
发表评论 共有条评论
用户名: 密码:
验证码: 匿名发表
相关文章
CopyRight 2008-2022, 529600.Net, Inc.All Rights Reserved
粤ICP备2022094815号-1  网安备案粤公网安备 44178102001207号