读书人

这段代码实现文字上下滚动一行,每次停

发布时间: 2012-02-15 12:09:43 作者: rapoo

这段代码实现文字上下滚动一行,每次停几秒,但有时这滚动的文字没有刚好占一行,大家帮忙改改?
<DIV id=icefable1>
<DIV id=box1left>
<LI> 商家: 6302203 人 供求信息数:11873180条 </LI>
<LI> 近期最新供应:1864084条 近期最新求购:28380 </LI>
</DIV>
</DIV>

<SCRIPT type=text/javascript>
marque(320,19, "icefable1 ", "box1left ")
var scrollElem;
var stopscroll;
var stoptime;
var preTop;
var leftElem;
var currentTop;
var marqueesHeight;
function marque(width,height,marqueName,marqueCName){
try{
marqueesHeight = height;
stopscroll = false;

scrollElem = document.getElementById(marqueName);
with(scrollElem){
style.width = width;
style.height = marqueesHeight;
style.overflow = 'hidden ';
noWrap = true;
}

scrollElem.onmouseover = new Function( 'stopscroll = true ');
scrollElem.onmouseout = new Function( 'stopscroll = false ');

preTop = 0;
currentTop = 0;
stoptime = 0;

leftElem = document.getElementById(marqueCName);
scrollElem.appendChild(leftElem.cloneNode(true));

init_srolltext();

}catch(e) {}
}
function init_srolltext(){
scrollElem.scrollTop = 0;
setInterval( 'scrollUp() ', 19);
}

function scrollUp(){
if(stopscroll) return;
currentTop += 1;
if(currentTop == marqueesHeight+1) {
stoptime += 1;
currentTop -= 1;
if(stoptime == (marqueesHeight)*4) {//停顿时间
currentTop = 0;
stoptime = 0;
}
}else{

preTop = scrollElem.scrollTop;
scrollElem.scrollTop += 1;
if(preTop == scrollElem.scrollTop){
scrollElem.scrollTop = marqueesHeight;
scrollElem.scrollTop += 1;
}
}
}
</SCRIPT>

要实现的效果如 阿里巴巴首页滚动文字那样(http://www.alibaba.com.cn)?谢谢.

[解决办法]
marque(320,19, "icefable1 ", "box1left ")--> marque(320,15, "icefable1 ", "box1left ")


调一下上下滚动的尺寸试试
[解决办法]
<html>
<head>
<style>
</style>
</head>
<body>
<DIV id=icefable1>
<DIV id=box1left>
<LI style= "line-height:19px "> 商家: 6302203 人 供求信息数:11873180条 </LI>
<LI style= "line-height:19px "> 近期最新供应:1864084条 近期最新求购:28380 </LI>
<LI style= "line-height:19px "> 近期最新供应:1864084条 近期最新求购:28380 </LI>
<LI style= "line-height:19px "> 近期最新供应:1864084条 近期最新求购:28380 </LI>
<LI style= "line-height:19px "> 近期最新供应:1864084条 近期最新求购:28380 </LI>
</DIV>
</DIV>

<SCRIPT type=text/javascript>
marque(320,19, "icefable1 ", "box1left ")
var scrollElem;
var stopscroll;
var stoptime;
var preTop;
var leftElem;
var currentTop;
var marqueesHeight;
function marque(width,height,marqueName,marqueCName){
try{
marqueesHeight = height;
stopscroll = false;

scrollElem = document.getElementById(marqueName);
with(scrollElem){
style.width = width;
style.height = marqueesHeight;
style.overflow = 'hidden ';
noWrap = true;
}

scrollElem.onmouseover = new Function( 'stopscroll = true ');
scrollElem.onmouseout = new Function( 'stopscroll = false ');

preTop = 0;
currentTop = 0;
stoptime = 0;

leftElem = document.getElementById(marqueCName);
scrollElem.appendChild(leftElem.cloneNode(true));

init_srolltext();

}catch(e) {}
}
function init_srolltext(){
scrollElem.scrollTop = 0;
setInterval( 'scrollUp() ', 19);
}

function scrollUp(){
if(stopscroll) return;
currentTop += 1;
if(currentTop == marqueesHeight+1) {
stoptime += 1;
currentTop -= 1;
if(stoptime == (marqueesHeight)*4) {//停顿时间
currentTop = 0;
stoptime = 0;
}
}else{

preTop = scrollElem.scrollTop;
scrollElem.scrollTop += 1;
if(preTop == scrollElem.scrollTop){
scrollElem.scrollTop = marqueesHeight;
scrollElem.scrollTop += 1;
}
}
}
</SCRIPT>


</body>
</html>


就可以了
[解决办法]
<%
dim toparr(4),topstr
toparr(0)= "【 "&date& "】亲爱的朋友,欢迎你来到小何的IT家园,希望你能在这里过的快乐! "
toparr(1)= "【 "&date& "】本博客域名 www.uschinateam.com,现诚邀友情链接,有意者请到申请友情链接处 <a href= 'index.asp?content=weburl '> 提交申请。 </a> "
toparr(2)= "【 "&date& "】本博客遵循创作共用原则,部分资源来自于互联网,如有侵权请留言通知,管理员会立即删除。 "
toparr(3)= "【 "&date& "】建议使用浏览器IE5.0+,分辨率1024*768浏览本站。 "
toparr(4)= "【 "&date& "】如果你使用的是FireFox请先下载 <a href= 'http://addons.mozine.org/firefox/53 ' target= '_blank '> IE Tab </a> 插件 "

topmarqueestext= " "
for topma=0 to UBound(toparr)
topmarqueestext=topmarqueestext& " <tr height= '15 ' align= 'center '> <td> 公告: "&toparr(topma)& " </td> </tr> "
next
topmarqueestext=topmarqueestext&topmarqueestes%>
<div id= "toptopmarquess ">
<table border= '0 ' cellspacing= '0 ' cellpadding= '0 '> <tr> <td> <div style= "display:none; font-size:12px; " id= 'topmarquees ' > <table width= "100% " border= '0 ' cellspacing= '0 ' cellpadding= '0 '>


<%=topmarqueestext%>
</table> </div> </td> </tr> </table>
</div>
<script language= "javascript " type= "text/javascript ">
<!--

topmarqueesheight=16;
stopscroll2=false;
with(topmarquees){
//noWrap=true;
//style.width=0;
style.height=topmarqueesheight;
style.overflowY= "hidden ";
onmouseover=new Function( "stopscroll2=true ");
onmouseout=new Function( "stopscroll2=false ");
}
times=8;

preLeft2=0;
timei2=0;
function timevalue2(s){
if ( timei2++ <s){
setTimeout( "timevalue2( "+s+ "); ",1000);
}
else{
scrollUp2();
}
}
function scrollUp2(){

if(!stopscroll2){
preLeft2=topmarquees.scrollTop+1;
topmarquees.scrollTop+=1;
}

if (preLeft2%16==0){
timei2=0;
setTimeout( "timevalue2( "+times+ "); ",1);
return ;
}

if(preLeft2> =16* <%=UBound(toparr)+1%> ){
topmarquees.scrollTop=1;
preLeft2=0;
}
setTimeout( "scrollUp2() ",20);
}
-->
</script>

读书人网 >JavaScript

热点推荐