百度空间 | 百度首页 
 
查看文章
 
兼容IE6,IE7的图片循环滚动,无间断图片滚动,JS图片滚动
2009-11-10 13:45
<div id="demo" style="overflow:hidden;width:754px; margin:0 auto;">
   <table align="center" cellpadding="0" cellspacing="0" border="0">
     <tr>
       <td id="demo1"><table width="98%" border="0" cellpadding="0" cellspacing="2">
           <tr>
             <td><img src="" width="120" height="90" alt="a" /></td>
             <td><img src="" width="120" height="90" alt="b" /></td>
             <td><img src="" width="120" height="90" alt="c" /></td>
             <td><img src="" width="120" height="90" alt="d" /></td>
             <td><img src="" width="120" height="90" alt="e" /></td>
             <td><img src="" width="120" height="90" alt="f" /></td>
             <td><img src="" width="120" height="90" alt="g" /></td>
             <td><img src="" width="120" height="90" alt="h" /></td>
             <td><img src="" width="120" height="90" alt="i" /></td>
             <td><img src="" width="120" height="90" alt="j" /></td>
             <td><img src="" width="120" height="90" alt="k" /></td>
             <td><img src="" width="120" height="90" alt="l" /></td>
             <td><img src="" width="120" height="90" alt="m" /></td>
             <td><img src="" width="120" height="90" alt="n" /></td>
             <td><img src="" width="120" height="90" alt="o" /></td>
           </tr>
         </table></td>
       <td id="demo2"></td>
     </tr>
   </table>
</div>
<script language="JavaScript">
     var speed=20;
     demo2.innerHTML=demo1.innerHTML;     //克隆demo1为demo2
    
     function Marquee(){
         if(demo2.offsetWidth   <= demo.scrollLeft){     //当滚动至demo1与demo2交界时
             demo.scrollLeft = demo.scrollLeft - demo1.offsetWidth;         //demo跳到最顶端
         }
         else{
             demo.scrollLeft++;
         }
     }
     var MyMar=setInterval(Marquee,speed);     //设置定时器
     demo.onmouseover=function() {clearInterval(MyMar);}//鼠标移上时清除定时器达到滚动停止的目的
     demo.onmouseout=function() {MyMar=setInterval(Marquee,speed);}//鼠标移开时重设定时器
</script>

类别:Javascript | 添加到搜藏 | 浏览() | 评论 (0)
 
最近读者:
 
网友评论:
发表评论:
姓 名:
网址或邮箱: (选填)
内 容:
验证码: 请点击后输入四位验证码,字母不区分大小写
      

     

©2009 Baidu