脚本循环滚动

 <script language="javascript" type="text/javascript">
        window.onload = function(){
                        
            MarqueeStart("marqueeImage",1,878,130,20,0,"table");
            MarqueeStart("guester",2,250,310,20,0,"dl");
            MarqueeStart("bbsHero",2,250,310,20,0,"dl"); 
            
        }

function Marquee(MarName)
{
    this.ID = document.getElementById(MarName);
    this.Speed = 30; //数字越大速度越慢
    this.Direction = 0;//滚动方向:0代表左;1代表右;2代表上;3代表下
    this.Width = 0;//高度
    this.Height = 0;//宽度
    this.Space = 0;//是否有间隙:0代表否;1代表是
    this.Tag = "p";//滚动内容的标签,默认是<p>,也可以是<ul>,实践证明:<p>与<ul>不能嵌套使用。其他标签暂时不推荐。
    //开始滚动    
    this.Start = function(){
        MarqueeStart(this,this.Direction,this.Width,this.Height,this.Speed,this.Space,this.Tag);
    }
    //停止滚动并释放对象
    this.End = function(){
        MarqueeEnd(this);
    }
}

function MarqueeStart(Mar,Direction,Width,Height,Speed,Space,Tag){  
    var msobj;
    if(typeof(Mar) == "string"){
        msobj = new Marquee(Mar);
    }
    if(typeof(Mar) == "object"){
        msobj = Mar;
    }
    if(!msobj.ID) return;
    msobj.ID.style.width = Width + "px";
    msobj.ID.style.height = Height + "px";
    msobj.ID.style.overflow = msobj.ID.style.overflowX = msobj.ID.style.overflowY = "hidden";
    msobj.Direction = Direction;
    msobj.Width = Width;
    msobj.Height = Height;
    msobj.Speed = Speed;
    msobj.Space = Space;
    msobj.Tag = Tag;
    msobj.InnerDiv = msobj.ID.getElementsByTagName("div")[0];
    if(!msobj.InnerDiv) return;
    msobj.InnerDiv.innerHTML += msobj.InnerDiv.innerHTML;
    msobj.Inner = msobj.ID.getElementsByTagName(Tag);
    if(!msobj.Inner) return;
    switch(Direction)
    {    
        case 2:        
            msobj.InnerDiv.style.width = Width + "px";
            msobj.Inner[0].style.width =Width + "px";
            msobj.Inner[1].style.width =Width + "px";
            if(Height>=msobj.Inner[1].offsetHeight || msobj.Space ==1){
                msobj.Inner[0].style.paddingTop = Height + "px";
                msobj.Inner[1].style.paddingTop = Height + "px";;
            }    
            break;
        case 3:
            msobj.InnerDiv.style.width = Width + "px";
            msobj.Inner[0].style.width =Width + "px";
            msobj.Inner[1].style.width =Width + "px";            
            if(Height>=msobj.Inner[1].offsetHeight || msobj.Space ==1){
                msobj.Inner[0].style.paddingBottom = Height + "px";
                msobj.Inner[1].style.paddingBottom = Height + "px";
            }
            break;
        default:            
            msobj.InnerDiv.noWrap = true;
            if(Width >= msobj.Inner[1].offsetWidth || msobj.Space ==1){
                msobj.Inner[0].style.paddingLeft = Width + "px";
                msobj.Inner[1].style.paddingLeft = Width + "px";
            }
            break;
    }
    
    msobj.ID.onmouseover = function(){
        clearInterval(msobj.TimerID);
    }
    
    msobj.ID.onmouseout = function(){
        clearInterval(msobj.TimerID);
        msobj.TimerID = funcInterval(MarqueeScroll,msobj.Speed,msobj);
    }
    msobj.TimerID = funcInterval(MarqueeScroll,msobj.Speed,msobj);    
    
}

function MarqueeScroll(Mar){        
    switch(Mar.Direction)
    {
        case 0:    
            if(Mar.Inner[1].offsetWidth-Mar.ID.scrollLeft<=0)
                Mar.ID.scrollLeft-=Mar.Inner[0].offsetWidth;
            else{                    
                Mar.ID.scrollLeft++;
            }
        break;
        case 1:                
            if(Mar.ID.scrollLeft==0)
                Mar.ID.scrollLeft=Mar.Inner[1].offsetWidth;
            else{
                Mar.ID.scrollLeft--;
            }                
        break;
        case 2:                
            if(Mar.Inner[1].offsetHeight-Mar.ID.scrollTop<=0)
                Mar.ID.scrollTop-=Mar.Inner[0].offsetHeight;
            else{
                Mar.ID.scrollTop++;
            }
        break;
        case 3:                
            if(Mar.ID.scrollTop<=0)
                Mar.ID.scrollTop = Mar.Inner[1].offsetHeight;
            else{
                Mar.ID.scrollTop--;
            }        
        break;
    }
}

function MarqueeEnd(Mar){
    if(!Mar)return;
    if(typeof(Mar.TimerID) == "number") {
        clearInterval(Mar.TimerID);
        Mar = null;
    }
}

function funcInterval(funcName,time){
  var args=[];
  for(var i=2;i<arguments.length;i++){
      args.push(arguments[i]);
  }
  return window.setInterval(function(){
            funcName.apply(this,args);
        },time);
}
</script>



 <div id="marqueeImage" >
     <div style="width:870px;">
            <!--产品开始-->
             <table cellspacing="0" cellpadding="3" align="center" border="0" >
                  <tr>
                     {/foreach from=$data.c_rollImages->ContentList item=entry name="ww"/}
                   <td width="157" height="116">
                 <a href="{/$entry->Link/}" rel="lightbox" title="{/$entry->Title/}">
                  <img src="{/$entry->ImageUrl/}" border="0" class="img_border1" /></a></td>
                     {//foreach/}
                      </tr>
                   </table>
                        <!--产品结束-->
                          </div>
              </div>



 <div id="bbsHero" >
          <div > <dl>
             {/foreach from=$data.c_bbshero->ContentList item=entry name="ww"/}
              <p style="height: 30px;">
              <img alt="" src="{/$entry->ImageUrl/}" />{/$entry->Title/}</p>
              {//foreach/}
             </dl>
          </div>
  </div>
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值