使用Javascript制作连续滚动字幕
发布网友
发布时间:2022-04-24 01:02
我来回答
共1个回答
热心网友
时间:2022-04-22 20:51
看的头大了,干脆给你个无缝滚动的代码吧
<div id="A1">
<div id="A2">
<div> ·我会滚动</div>
<div> ·我会滚动</div>
<div> ·我会滚动</div>
<div> ·我会滚动</div>
<div> ·我会滚动</div>
<div> ·我会滚动</div>
<div> ·我会滚动</div>
<div> ·我会滚动</div>
<div> ·我会滚动</div>
<div> ·我会滚动</div>
</div>
</div>
<SCRIPT language=JavaScript>
<!--
function _InitScroll(_S1,_S2,_W,_H,_T){
return "var marqueesHeight"+_S1+"="+_H+";var stopscroll"+_S1+"=false;var scrollElem"+_S1+"=document.getElementById('"+_S1+"');with(scrollElem"+_S1+"){style.width="+_W+";style.height=marqueesHeight"+_S1+";style.overflow='hidden';noWrap=true;}scrollElem"+_S1+".onmouseover=new Function('stopscroll"+_S1+"=true');scrollElem"+_S1+".onmouseout=new Function('stopscroll"+_S1+"=false');var preTop"+_S1+"=0; var currentTop"+_S1+"=0; var stoptime"+_S1+"=0;var leftElem"+_S2+"=document.getElementById('"+_S2+"');scrollElem"+_S1+".appendChild(leftElem"+_S2+".cloneNode(true));setTimeout('init_srolltext"+_S1+"()',"+_T+");function init_srolltext"+_S1+"(){scrollElem"+_S1+".scrollTop=0;setInterval('scrollUp"+_S1+"()',10);}function scrollUp"+_S1+"(){if(stopscroll"+_S1+"){return;}currentTop"+_S1+"+=1;if(currentTop"+_S1+"==(marqueesHeight"+_S1+"+1)) {stoptime"+_S1+"+=1;currentTop"+_S1+"-=1;if(stoptime"+_S1+"=="+_T+") {currentTop"+_S1+"=0;stoptime"+_S1+"=0;}}else{preTop"+_S1+"=scrollElem"+_S1+".scrollTop;scrollElem"+_S1+".scrollTop +=1;if(preTop"+_S1+"==scrollElem"+_S1+".scrollTop){scrollElem"+_S1+".scrollTop=0;scrollElem"+_S1+".scrollTop +=1;}}}";
}
eval(_InitScroll("A1","A2",300,22*10,500));
//-->
</SCRIPT>