我想在页面上实现两个地方字幕滚动,我将下面代码分别复制两次放在页面里,只把容器ID改一下,可总是只有一个滚动,请问怎么实现两处或多处滚动呢??代码如下面:window.onload=function(){
new Marquee(
"aaleft_zj_tj", //容器ID<br />
0, //向上滚动(0向上 1向下 2向左 3向右)<br />
2, //滚动的步长<br />
663, //容器可视宽度<br />
155, //容器可视高度<br />
50, //定时器 数值越小,滚动的速度越快(1000=1秒,建议不小于20)<br />
2000, //间歇停顿时间(0为不停顿,1000=1秒)<br />
1000, //开始时的等待时间(0为不等待,1000=1秒)<br />
22 //间歇滚动间距(可选)<br />
);
};
function Marquee(){
this.ID=document.getElementById(arguments[0]);
this.Direction=arguments[1];
this.Step=arguments[2];
this.Width=arguments[3];
this.Height=arguments[4];
this.Timer=arguments[5];
this.WaitTime=arguments[6];
this.StopTime=arguments[7];
。以下省略
new Marquee(
"aaleft_zj_tj", //容器ID<br />
0, //向上滚动(0向上 1向下 2向左 3向右)<br />
2, //滚动的步长<br />
663, //容器可视宽度<br />
155, //容器可视高度<br />
50, //定时器 数值越小,滚动的速度越快(1000=1秒,建议不小于20)<br />
2000, //间歇停顿时间(0为不停顿,1000=1秒)<br />
1000, //开始时的等待时间(0为不等待,1000=1秒)<br />
22 //间歇滚动间距(可选)<br />
);
};
function Marquee(){
this.ID=document.getElementById(arguments[0]);
this.Direction=arguments[1];
this.Step=arguments[2];
this.Width=arguments[3];
this.Height=arguments[4];
this.Timer=arguments[5];
this.WaitTime=arguments[6];
this.StopTime=arguments[7];
。以下省略
window.onload=function(){
new Marquee(
"aareg_bot", //容器ID<br />
0, //向上滚动(0向上 1向下 2向左 3向右)<br />
2, //滚动的步长<br />
323, //容器可视宽度<br />
100, //容器可视高度<br />
50, //定时器 数值越小,滚动的速度越快(1000=1秒,建议不小于20)<br />
2000, //间歇停顿时间(0为不停顿,1000=1秒)<br />
1000, //开始时的等待时间(0为不等待,1000=1秒)<br />
22 //间歇滚动间距(可选)<br />
);
};
function Marquee(){
this.ID=document.getElementById(arguments[0]);
this.Direction=arguments[1];
this.Step=arguments[2];
this.Width=arguments[3];
this.Height=arguments[4];
this.Timer=arguments[5];
this.WaitTime=arguments[6];
this.StopTime=arguments[7];
if(arguments[8]){this.ScrollStep=arguments[8];}else{this.ScrollStep=this.Direction>1?this.Width:this.Height;}
this.CTL=this.StartID=this.Stop=this.MouseOver=0;
this.ID.style.overflowX=this.ID.style.overflowY="hidden";
this.ID.noWrap=true;
this.ID.style.width=this.Width;
this.ID.style.height=this.Height;
this.ClientScroll=this.Direction>1?this.ID.scrollWidth:this.ID.scrollHeight;
this.ID.innerHTML+=this.ID.innerHTML;
this.Start(this,this.Timer,this.WaitTime,this.StopTime);
}
Marquee.prototype.Start=function(msobj,timer,waittime,stoptime){
msobj.StartID=function(){msobj.Scroll();}
msobj.Continue=function(){
if(msobj.MouseOver==1){setTimeout(msobj.Continue,waittime);}
else{clearInterval(msobj.TimerID); msobj.CTL=msobj.Stop=0; msobj.TimerID=setInterval(msobj.StartID,timer);}
}
msobj.Pause=function(){msobj.Stop=1; clearInterval(msobj.TimerID); setTimeout(msobj.Continue,waittime);}
msobj.Begin=function(){
msobj.TimerID=setInterval(msobj.StartID,timer);
msobj.ID.onmouseover=function(){msobj.MouseOver=1; clearInterval(msobj.TimerID);}
msobj.ID.onmouseout=function(){msobj.MouseOver=0; if(msobj.Stop==0){clearInterval(msobj.TimerID); msobj.TimerID=setInterval(msobj.StartID,timer);}}
}
setTimeout(msobj.Begin,stoptime);
}
Marquee.prototype.Scroll=function(){
switch(this.Direction){
case 0:
this.CTL+=this.Step;
if(this.CTL>=this.ScrollStep&&this.WaitTime>0){this.ID.scrollTop+=this.ScrollStep+this.Step-this.CTL; this.Pause(); return;}
else{if(this.ID.scrollTop>=this.ClientScroll) this.ID.scrollTop-=this.ClientScroll; this.ID.scrollTop+=this.Step;}
break;
case 1:
this.CTL+=this.Step;
if(this.CTL>=this.ScrollStep&&this.WaitTime>0){this.ID.scrollTop-=this.ScrollStep+this.Step-this.CTL; this.Pause(); return;}
else{if(this.ID.scrollTop<=0) this.ID.scrollTop+=this.ClientScroll; this.ID.scrollTop-=this.Step;}
break;
case 2:
this.CTL+=this.Step;
if(this.CTL>=this.ScrollStep&&this.WaitTime>0){this.ID.scrollLeft+=this.ScrollStep+this.Step-this.CTL; this.Pause(); return;}
else{if(this.ID.scrollLeft>=this.ClientScroll) this.ID.scrollLeft-=this.ClientScroll; this.ID.scrollLeft+=this.Step;}
break;
case 3:
this.CTL+=this.Step;
if(this.CTL>=this.ScrollStep&&this.WaitTime>0){this.ID.scrollLeft-=this.ScrollStep+this.Step-this.CTL; this.Pause(); return;}
else{if(this.ID.scrollLeft<=0) this.ID.scrollLeft+=this.ClientScroll; this.ID.scrollLeft-=this.Step;}
break;
}
}
使用的代码就是这上面的,我现在想在同一个页面使用两次
晕,都不好改,给你一个简单的代码吧,功能冒似一样的
<div id="box1" style="width:400px;height:90px;overflow:hidden;" onload="mystr(this)">恒顺高级幼稚园为四完小患病学生奉献爱心<br>2009年郴州春季车展将于5月15日盛大举行<br>我省第七届少数民族运动会将于明年在我市举行恒顺高级幼稚园为四完小患病学生奉献爱心<br>2009年郴州春季车展将于5月15日盛大举行<br>我省第七届少数民族运动会将于明年在我市举行恒顺高级幼稚园为四完小患病学生奉献爱心<br>2009年郴州春季车展将于5月15日盛大举行<br>我省第七届少数民族运动会将于明年在我市举行恒顺高级幼稚园为四完小患病学生奉献爱心<br>2009年郴州春季车展将于5月15日盛大举行<br>我省第七届少数民族运动会将于明年在我市举行</div>
<script>
var oMarquee = document.getElementById("box1"); //滚动对象
var iLineHeight = 18; //单行高度,像素
var iLineCount = 18; //实际行数
var iScrollAmount = 1; //每次滚动高度,像素
function run() {
oMarquee.scrollTop += iScrollAmount;
if ( oMarquee.scrollTop == iLineCount * iLineHeight )
oMarquee.scrollTop = 0;
if ( oMarquee.scrollTop % iLineHeight == 0 ) {
window.setTimeout( "run()", 3000 );
} else {
window.setTimeout( "run()", 50 );
}
}
oMarquee.innerHTML += oMarquee.innerHTML;
window.setTimeout( "run()", 2000 );
</script>
int i;
i=0;
i=1;
你说最后i应该等于几?
JS中也是一样的,进行两次赋值,后一次的的赋值会将第一的赋值冲掉
new Marquee(
"aareg_bot", //容器ID
0, //向上滚动(0向上 1向下 2向左 3向右)
2, //滚动的步长
323, //容器可视宽度
100, //容器可视高度
50, //定时器 数值越小,滚动的速度越快(1000=1秒,建议不小于20)
2000, //间歇停顿时间(0为不停顿,1000=1秒)
1000, //开始时的等待时间(0为不等待,1000=1秒)
22 //间歇滚动间距(可选)
);
new Marquee(
"aareg_bot__2", //容器ID
0, //向上滚动(0向上 1向下 2向左 3向右)
2, //滚动的步长
323, //容器可视宽度
100, //容器可视高度
50, //定时器 数值越小,滚动的速度越快(1000=1秒,建议不小于20)
2000, //间歇停顿时间(0为不停顿,1000=1秒)
1000, //开始时的等待时间(0为不等待,1000=1秒)
22 //间歇滚动间距(可选)
);
};(代码不须复制两次^_^)