无缝文字滚动

一个常见的无缝文字滚动,结合CSS构建的区域形成即时新闻列表,与常见滚动有所不同的是,我们增加了手动控制,即:如果文字滚动错过了想要看的文章标题,您可以按向上或向下的控制按钮进行返回操作。


文章源自:烈火网,原文:http://www.veryhuo.com/a/view/26106.html

<html>
<head>
<title>可控制文字列表上下滚动效果</title>
<meta http-equiv="content-type" content="text/html; charset=gbk" />
<style>
body, div, dl, dt, dd, ul, ol, li, h1, h2, h3, h4, h5, h6, pre, form, fieldset, input, p, blockquote, th, td {margin:0;padding:0; font-size:12px;}
li{ list-style:none;}
ul{ margin:0;}
a{ color:#0066CC; text-decoration:none;}
a:hover{ color:#FF0000; text-decoration: underline;}
.breakNewsblock {
margin:0 auto;
position:relative;
width:276px;
overflow:hidden;
}
.breakNewsblock h2 {
background:transparent url(/uploads/allimg/1009/icon.gif) no-repeat scroll 7px -307px;
color:#8F1D21;
float:left;
font-size:12px;
padding-left:25px;
}
.breakNewsblock h2 span{ float:right; padding-right:10px;}
#breakNews {
background:transparent url(/uploads/allimg/1009/backbar.gif) no-repeat scroll center top;float:left;height:138px;
margin-top:5px;
padding:0 0 3px 2px;
width:275px;
}
#breakNews .list6 {color:#333333;float:left;height:115px;margin-top:11px;overflow:hidden;width:240px; padding-left:10px;
}
#breakNews .list6 li{ padding:3px 0;}
#breakNews .hit {float:right;height:24px; margin-top:23px; width:17px;}
#breakNews .hit span { display:block;float:left;height:13px; margin-bottom:6px;width:13px;}
</style>
<script language="javascript" type="text/javascript">
function ScrollText(content,btnPrevious,btnNext,autoStart,timeout,isSmoothScroll)
{
this.Speed = 10;//滚动速度
this.Timeout = timeout;
this.stopscroll =false;//是否停止滚动的标志位
this.isSmoothScroll= isSmoothScroll;//是否平滑连续滚动
this.LineHeight = 20;//默认高度。可以在外部根据需要设置
this.NextButton = this.$(btnNext);
this.PreviousButton = this.$(btnPrevious);
this.ScrollContent = this.$(content);
this.ScrollContent.innerHTML += this.ScrollContent.innerHTML;//为了平滑滚动再加一遍
if(this.PreviousButton)
{
this.PreviousButton.onclick = this.GetFunction(this,"Previous");
this.PreviousButton.onmouseover = this.GetFunction(this,"MouseOver");
this.PreviousButton.onmouseout = this.GetFunction(this,"MouseOut");
}
if(this.NextButton){
this.NextButton.onclick = this.GetFunction(this,"Next");
this.NextButton.onmouseover = this.GetFunction(this,"MouseOver");
this.NextButton.onmouseout = this.GetFunction(this,"MouseOut");
}
this.ScrollContent.onmouseover = this.GetFunction(this,"MouseOver");
this.ScrollContent.onmouseout = this.GetFunction(this,"MouseOut");
if(autoStart)
{
this.Start();
}
}
ScrollText.prototype = {
$:function(element)
{
return document.getElementById(element);
},
Previous:function()
{
this.stopscroll = true;
this.Scroll("up");
},
Next:function()
{
this.stopscroll = true;
this.Scroll("down");
},
Start:function()
{
if(this.isSmoothScroll)
{
this.AutoScrollTimer = setInterval(this.GetFunction(this,"SmoothScroll"), this.Timeout);
}
else
{
this.AutoScrollTimer = setInterval(this.GetFunction(this,"AutoScroll"), this.Timeout);
}
},
Stop:function()
{
clearTimeout(this.AutoScrollTimer);
this.DelayTimerStop = 0;
},
MouseOver:function()
{
this.stopscroll = true;
},
MouseOut:function()
{
this.stopscroll = false;
},
AutoScroll:function()
{
if(this.stopscroll)
{
return;
}
this.ScrollContent.scrollTop++;
if(parseInt(this.ScrollContent.scrollTop) % this.LineHeight != 0)
{
this.ScrollTimer = setTimeout(this.GetFunction(this,"AutoScroll"), this.Speed);
}
else
{
if(parseInt(this.ScrollContent.scrollTop) >= parseInt(this.ScrollContent.scrollHeight) / 2)
{
this.ScrollContent.scrollTop = 0;
}
clearTimeout(this.ScrollTimer);
//this.AutoScrollTimer = setTimeout(this.GetFunction(this,"AutoScroll"), this.Timeout);
}
},
SmoothScroll:function()
{
if(this.stopscroll)
{
return;
}
this.ScrollContent.scrollTop++;
if(parseInt(this.ScrollContent.scrollTop) >= parseInt(this.ScrollContent.scrollHeight) / 2)
{
this.ScrollContent.scrollTop = 0;
}
},
Scroll:function(direction)
{
if(direction=="up")
{
this.ScrollContent.scrollTop--;
}
else
{
this.ScrollContent.scrollTop++;
}
if(parseInt(this.ScrollContent.scrollTop) >= parseInt(this.ScrollContent.scrollHeight) / 2)
{
this.ScrollContent.scrollTop = 0;
}
else if(parseInt(this.ScrollContent.scrollTop)<=0)
{
this.ScrollContent.scrollTop = parseInt(this.ScrollContent.scrollHeight) / 2;
}
if(parseInt(this.ScrollContent.scrollTop) % this.LineHeight != 0)
{
this.ScrollTimer = setTimeout(this.GetFunction(this,"Scroll",direction), this.Speed);
}
},
GetFunction:function(variable,method,param)
{
return function()
{
variable[method](param);
}
}
}
function ignoreError() {
return true;
}
window.onerror = ignoreError;
</script>
</head>
<body>
<div class="breakNewsblock">
<h2><a target="_blank" href="#">即时新闻</a></h2>
<div id="breakNews">
<ul id="breakNewsList" class="list6">
<li><a target="_blank" href="http://www.veryhuo.com/a/view/25671.html">百度MP3哼唱搜索悄悄上线 可通过旋律</a></li>
<li><a target="_blank" href="http://www.veryhuo.com/a/view/26072.html">盛大游戏获《最终幻想14》大陆独家运</a></li>
<li><a target="_blank" href="http://www.veryhuo.com/a/view/26071.html">百度在线输入法上线 占据首页重要位置</a></li>
<li><a target="_blank" href="http://www.veryhuo.com/a/view/26068.html">腾讯SNS平台开放:开发者担忧开放性</a></li>
<li><a target="_blank" href="http://www.veryhuo.com/a/view/26061.html">百度推微博(t.baidu.com)内测,取名百度</a></li>
<li><a target="_blank" href="http://www.veryhuo.com/a/view/26022.html">盛大和CNTV.CN成立合资游戏公司易橙天</a></li>
<li><a target="_blank" href="http://www.veryhuo.com/a/view/26021.html">MSN推出中文网址导航 定位白领用户生活</a></li>
<li><a target="_blank" href="http://www.veryhuo.com/a/view/25988.html">phpwind站长交流会石家庄站本月18日召开</a></li>
<li><a target="_blank" href="http://www.veryhuo.com/a/view/26020.html">7K7K流量逼近4399 hao123游戏导航栏悄然</a></li>
<li><a target="_blank" href="http://www.veryhuo.com/a/view/25947.html">传4399出售谈判近尾声 蔡文胜亮底价待</a></li>
<li><a target="_blank" href="http://www.veryhuo.com/a/view/25900.html">最大域名注册商GoDaddy或将10亿美元</a></li>
<li><a target="_blank" href="http://www.veryhuo.com/a/view/25509.html">网易邮箱及有道翻译实现百度搜索即搜</a></li>
<li><a target="_blank" href="http://www.veryhuo.com/a/view/25485.html">微软Bing可视化搜索之“魔兽世界”上</a></li>
<li><a target="_blank" href="http://www.veryhuo.com/a/view/25425.html">百度联盟推出网盟推广“邀请.返利”活</a></li>
</ul>
<div class="hit">
<span><a style="cursor: pointer;"><img width="11" height="10" id="pre2" alt="上一条" src="/uploads/allimg/1009/none.gif"/></a></span>
<span><a style="cursor: pointer;"><img width="11" height="10" id="next2" alt="下一条" src="/uploads/allimg/1009/none.gif"/></a></span>
</div>
</div>
</div>
<script language="javascript" type="text/javascript">
var scroll2 = new ScrollText("breakNewsList","pre2","next2",true,70,true);
scroll2.LineHeight = 24;
</script>
</body>
</html><br /><center>如不能显示效果,请按Ctrl+F5刷新本页,更多网页代码:<a href='http://www.veryhuo.com/' target='_blank'>http://www.veryhuo.com/</a></center>
文章源自:烈火网,原文:http://www.veryhuo.com/a/view/26106.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值