电脑技术学习

JS新闻无缝滚动封装函数

dn001

程序代码

<script type="text/javascript">
<!--
//新闻滚动JS代码 (一次滚动高度,速度,停留时间,图层标记)
function startmarquee(lh,speed,delay,index){
var t;
var p=false;
var o=$("gundongnews"+index);
o.innerHTML+=o.innerHTML;
o.onmouseover=function(){p=true}
o.onmouseout=function(){p=false}
o.scrollTop = 0;
function start(){
t=setInterval(scrolling,speed);
if(!p) o.scrollTop += 2;
}
function scrolling(){
if(o.scrollTop%lh!=0){
o.scrollTop += 2;
if(o.scrollTop>=o.scrollHeight/2) o.scrollTop = 0;
}
else{
clearInterval(t);
setTimeout(start,delay);
}
}
setTimeout(start,delay);
}
//-->
</script>

调用举例:


程序代码

<div id="other">
<ul id="gundongnews0">
<li>1</li>
<li>1</li>
<li>1</li>
</ul>
</div>
<script language="JavaScript" type="text/javascript">startmarquee(18,30,3000,0); </script>

20090129 还需要定义样式:


程序代码

/* 滚动文字 */
#other{ float:left; height: 18px; line-height:18px; padding:3px 0; width: 100%; margin:0; overflow: hidden;}
#gundongnews0,#gundongnews0 li{ clear:both; color:#FF6600; padding: 0px;height: 18px;overflow: hidden; line-height:18px }
#gundongnews0 a{ color:#FF6600;}