05
2013-11

JS向上滚动代码

js向上滚动代码,直接上代码:

<style type="text/css">
 #scroll{width:230px; height:490px;  overflow:hidden;  }/*line-height是每次移动的距离,overflow;hidden 也不能省*/
</style>
<script type="text/javascript">
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;
    }
  }
</script>
</head>
      
<div id="scroll">
  <!--总共有三个scroll id,都改成一样边可通用;-->
              <p style="font-size:14px; font-weight:bold; line-height:24px;padding-left:10px; padding-top:10px; padding-bottom:10px;"><a href="http://www.eeworld.com.cn/training/index.php?m=content&c=tag&a=lists&tag=DLP" target="_blank"><img src="images/DLP.jpg" width="80" height="80" style="vertical-align:middle"></a><span style="padding-left:10px;"><a href="http://www.eeworld.com.cn/training/index.php?m=content&c=tag&a=lists&tag=DLP" target="_blank">DLP精品课程</a></span></p>
      
              <p style="font-size:14px; font-weight:bold; line-height:24px; padding-left:10px; padding-top:10px; padding-bottom:10px;"><a href="http://www.eeworld.com.cn/training/index.php?m=content&c=tag&a=lists&tag=MCU" target="_blank"><img src="images/MCU.jpg" width="80" height="80" style="vertical-align:middle"></a><span style="padding-left:10px;"><a href="http://www.eeworld.com.cn/training/index.php?m=content&c=tag&a=lists&tag=MCU" target="_blank">MCU精品课程</a></span></p>
      
              <p style="font-size:14px; font-weight:bold; line-height:24px; padding-left:10px; padding-top:10px; padding-bottom:10px;"><a href="http://www.eeworld.com.cn/training/index.php?m=content&c=tag&a=lists&tag=%B5%E7%D4%B4" target="_blank"><img src="images/MCU.jpg" width="80" height="80" style="vertical-align:middle"></a><span style="padding-left:10px;"><a href="http://www.eeworld.com.cn/training/index.php?m=content&c=tag&a=lists&tag=%B5%E7%D4%B4" target="_blank">电源精品课程</a></span></p>
      
              <p style="font-size:14px; font-weight:bold; line-height:24px; padding-left:10px; padding-top:10px; padding-bottom:10px;"><a href="http://www.eeworld.com.cn/training/index.php?m=content&c=tag&a=lists&tag=DSP" target="_blank"><img src="images/DSP.jpg" width="80" height="80" style="vertical-align:middle"></a><span style="padding-left:10px;"><a href="http://www.eeworld.com.cn/training/index.php?m=content&c=tag&a=lists&tag=DSP" target="_blank">DSP精品课程</a></span></p>
      
              <p style="font-size:14px; font-weight:bold; line-height:24px; padding-left:10px; padding-top:10px; padding-bottom:10px;"><a href="http://www.eeworld.com.cn/training/index.php?m=content&c=tag&a=lists&tag=%CE%DE%CF%DF" target="_blank"><img src="images/wireless.jpg" width="80" height="80" style="vertical-align:middle"></a><span style="padding-left:10px;"><a href="http://www.eeworld.com.cn/training/index.php?m=content&c=tag&a=lists&tag=%CE%DE%CF%DF" target="_blank">无线精品课程</a></span></p>
</div>
<script>
window.onload=function(){
  new Marquee(
    "scroll",  //容器ID<br />
    0,  //向上滚动(0向上 1向下 2向左 3向右)<br />
    2,  //滚动的步长<br />
    230,  //容器可视宽度<br />
    490,  //容器可视高度<br />
    50,  //定时器 数值越小,滚动的速度越快(1000=1秒,建议不小于20)<br />
    1000,  //间歇停顿时间(0为不停顿,1000=1秒)<br />
    1000,  //开始时的等待时间(0为不等待,1000=1秒)<br />
   100//间歇滚动间距(可选)<br />
    );
  };
</script>

除非注明,文章均为史亚永原创,欢迎转载!转载请注明本文地址,谢谢。

本文地址:http://www.shiyayong.cn/post/236.html

评论列表:

1  gzq1019  2014-7-1 16:01:47 回复该留言  IP:218.24.166.12
为什么在火狐里滚动就不太好用呢
gzq1019

发表评论:

(设置个性头像)

◎欢迎参与讨论,请在这里发表您的看法、交流您的观点。

无觅相关文章插件,快速提升流量