图片连续循环滚动代码(向上)

方法一、

<base

href="http://image2.sina.com.cn/gm/lineage2/whz/newwh/images/fy/images/images/ifimage/">

<div id=demo style="overflow:hidden; width:128px; height:300px;">
<div id=demo1>
<img src="gfjs.gif"><br><img src="bxtt.gif"><br><img src="bzjd.gif"><br>
<img src="gfjs.gif"><br><img src="bxtt.gif"><br><img src="bzjd.gif"><br>
<img src="gfjs.gif"><br><img src="bxtt.gif"><br><img src="bzjd.gif"><br>
<img src="gfjs.gif"><br><img src="bxtt.gif"><br><img src="bzjd.gif"><br>
<img src="gfjs.gif"><br><img src="bxtt.gif"><br><img src="bzjd.gif"><br>
<img src="gfjs.gif"><br><img src="bxtt.gif"><br><img src="bzjd.gif"><br>
<img src="gfjs.gif"><br><img src="bxtt.gif"><br><img src="bzjd.gif"><br>
<img src="gfjs.gif"><br><img src="bxtt.gif"><br><img src="bzjd.gif"><br>
<img src="gfjs.gif"><br><img src="bxtt.gif"><br><img src="bzjd.gif"><br>
<img src="gfjs.gif"><br><img src="bxtt.gif"><br><img src="bzjd.gif"><br>
<img src="gfjs.gif"><br><img src="bxtt.gif"><br><img src="bzjd.gif"><br>
</div>
<div id=demo2></div>
</div>
<script language="javascript">
var speed=30
demo2.innerHTML=demo1.innerHTML
function Marquee(){
if(demo2.offsetTop-demo.scrollTop<=0)
demo.scrollTop-=demo1.offsetHeight
else{
demo.scrollTop++
}
}
var MyMar=setInterval(Marquee,speed)
demo.onmouseover=function() {clearInterval(MyMar)}
demo.onmouseout=function() {MyMar=setInterval(Marquee,speed)}
</script>


方法二、

 <div id="stable_2">
<TABLE border=0 cellSpacing=0 cellPadding=0  width="100%"  >
  <TR>
    <TD height="20" colspan="3"><A href=" http://blog.csdn.net/vince6799">1.连续无缝向上滚动</A></TD>
  </TR>
  <TR>
    <TD height="20" colspan="3"><A href=" http://blog.csdn.net/vince6799">2.连续无缝向上滚动</A></TD>
  </TR>
  <TR>
   <TD height="20" colspan="3"><A href=" http://blog.csdn.net/vince6799">3.连续无缝向上滚动</A></TD>
  </TR>
  <TR>
    <TD height="20" colspan="3"><A href=" http://blog.csdn.net/vince6799">4.连续无缝向上滚动</A></TD>
  </TR>
  <TR>
   <TD height="20" colspan="3"><A href=" http://blog.csdn.net/vince6799">5.连续无缝向上滚动</A></TD>
  </TR>
  <TR>
    <TD height="20" colspan="3"><A href=" http://blog.csdn.net/vince6799">6.连续无缝向上滚动</A></TD>
  </TR>
  <TR>
   <TD height="20" colspan="3"><A href=" http://blog.csdn.net/vince6799">7.连续无缝向上滚动---结束</A></TD>
   </TR>
</TABLE>
</div>
<script type="text/javascript">
function addEventSimple(obj,evt,fn)

 if(obj.addEventListener)
 {
  obj.addEventListener(evt,fn,false);
 }else if(obj.attachEvent)
   {
    obj.attachEvent('on'+evt,fn);
   }
 }
addEventSimple(window,'load',initScrolling);//保存想要滚动的容器
var scrollingBox;var scrollingInterval;//用于记录是否“滚到头”过一次
var reachedBottom=false;//记录第一次滚到头时候的scrollTopvar bottom;//初始化滚动效果
function initScrolling()
{
 scrollingBox = document.getElementById("stable_2"); //样式设置,与滚动基本无关,应该用CSS设置。 
 scrollingBox.style.height = "150px"; 
 scrollingBox.style.overflow = "hidden"; //滚动 
 scrollingInterval = setInterval("scrolling()",50); //鼠标划过停止滚动效果
 scrollingBox.onmouseover = over; //鼠标划出回复滚动效果 
 scrollingBox.onmouseout = out; 
}//滚动效果
function scrolling()
{ //开始滚动,origin是原来scrollTop 
 var origin = scrollingBox.scrollTop++; //如果到头了 
 if(origin == scrollingBox.scrollTop)
 {  //如果是第一次到头  
  if(!reachedBottom)
  {
   scrollingBox.innerHTML+=scrollingBox.innerHTML;
   reachedBottom=true;
   bottom=origin;
  }else{   //已经到头过,只需回复头接尾的效果
    scrollingBox.scrollTop=bottom;
     }
  }
}
function over()
{
 clearInterval(scrollingInterval);
}
function out()
{
 scrollingInterval = setInterval("scrolling()",50);
}
</script>

原文链接: http://blog.csdn.net/vince6799/article/details/2197241

你可能感兴趣的:(图片连续循环滚动代码(向上))