无缝连接、循环滚动的走马灯效果

JavaScript实现走马灯效果[无缝连接、循环滚动] 无缝跑马灯效果
以下代码在IE6、Firefox+Win2k环境下测试通过

一、向上的无缝循环滚动
HTML代码
<!-- 指向链接图片的URL --><base href="<a href="http://blog.ad0.cn" target="_blank">http://blog.ad0.cn</a>"><div align="center" id="demo" style="overflow:hidden;height:200px;width:95px;border-width:1px 1px 1px 1px;border-style:dotted dotted dotted dotted;">    <div id="demo1">        <!-- 定义内容-->        <img src="images/logo_1.gif">        <img src="images/logo/flashempire.gif">        <img src="images/logo.gif">        <img src="images/logo/5dmedia.gif">        <img src="images/logo/macromedia.gif">        <img src="images/logo/sucaiw.gif">        <img src="images/logo/blueieda.gif">        <img src="images/logo/htmlcn.gif">        <img src="images/logo/fwcn.gif">    </div>    <div id="demo2"></div></div><script language="javascript" type="text/javascript"><!--var demo = document.getElementById("demo");var demo1 = document.getElementById("demo1");var demo2 = document.getElementById("demo2");var speed=10;    //滚动速度值,值越大速度越慢demo2.innerHTML = demo1.innerHTML    //克隆demo2为demo1function Marquee(){    if(demo2.offsetTop-demo.scrollTop<=0)    //当滚动至demo1与demo2交界时        demo.scrollTop-=demo1.offsetHeight    //demo跳到最顶端    else{        demo.scrollTop++    }}var MyMar = setInterval(Marquee,speed);        //设置定时器demo.onmouseover = function(){clearInterval(MyMar)}    //鼠标经过时清除定时器达到滚动停止的目的demo.onmouseout = function(){MyMar = setInterval(Marquee,speed)}    //鼠标移开时重设定时器--></script>

[Ctrl+A 全部选择 提示:你可先修改部分代码,再按运行]



二、向下的无缝循环滚动
HTML代码
<!-- 指向链接图片的URL --><base href="<a href="http://blog.ad0.cn" target="_blank">http://blog.ad0.cn</a>"><div align="center" id="demo" style="overflow:hidden;height:200px;width:95px;border-width:1px 1px 1px 1px;border-style:dotted dotted dotted dotted;">    <div id="demo1">        <!-- 定义内容-->        <img src="images/logo_1.gif">        <img src="images/logo/flashempire.gif">        <img src="images/logo.gif">        <img src="images/logo/5dmedia.gif">        <img src="images/logo/macromedia.gif">        <img src="images/logo/sucaiw.gif">        <img src="images/logo/blueieda.gif">        <img src="images/logo/htmlcn.gif">        <img src="images/logo/fwcn.gif">    </div>    <div id="demo2"></div></div><script language="javascript" type="text/javascript"><!--var demo = document.getElementById("demo");var demo1 = document.getElementById("demo1");var demo2 = document.getElementById("demo2");var speed=10;    //数值越大滚动速度越慢demo2.innerHTML = demo1.innerHTML;demo.scrollTop = demo.scrollHeight;function Marquee(){    if(demo1.offsetTop-demo.scrollTop>=0)        demo.scrollTop+=demo2.offsetHeight    else{        demo.scrollTop--    }}var MyMar = setInterval(Marquee,speed);demo.onmouseover = function(){clearInterval(MyMar)}demo.onmouseout = function(){MyMar = setInterval(Marquee,speed)}--></script>

[Ctrl+A 全部选择 提示:你可先修改部分代码,再按运行]



三、向左的无缝循环滚动
HTML代码
<!-- 指向链接图片的URL --><base href="<a href="http://blog.ad0.cn" target="_blank">http://blog.ad0.cn</a>"><div align="center" id="demo" style="overflow:hidden;height:33px;width:500px;border-width:1px 1px 1px 1px;border-style:dotted dotted dotted dotted;">  <table border="0" cellspacing="0" cellpadding="0">    <tr>      <td id="demo1"><img src="images/logo_1.gif"><img src="images/logo/flashempire.gif"><img src="images/logo.gif"><img src="images/logo/5dmedia.gif"><img src="images/logo/macromedia.gif"><img src="images/logo/sucaiw.gif"><img src="images/logo/blueieda.gif"><img src="images/logo/htmlcn.gif" border="0"></td>      <td id="demo2"> </td>    </tr>  </table></div><script language="javascript" type="text/javascript"><!--var demo = document.getElementById("demo");var demo1 = document.getElementById("demo1");var demo2 = document.getElementById("demo2");var speed=10;    //数值越大滚动速度越慢demo2.innerHTML = demo1.innerHTMLfunction Marquee(){    if(demo2.offsetWidth-demo.scrollLeft<=0)        demo.scrollLeft-=demo1.offsetWidth    else{        demo.scrollLeft++    }}var MyMar = setInterval(Marquee,speed);demo.onmouseover = function(){clearInterval(MyMar)}demo.onmouseout = function(){MyMar = setInterval(Marquee,speed)}--></script>

[Ctrl+A 全部选择 提示:你可先修改部分代码,再按运行]



四、向右的无缝循环滚动
HTML代码
<!-- 指向链接图片的URL --><base href="<a href="http://blog.ad0.cn" target="_blank">http://blog.ad0.cn</a>"><div align="center" id="demo" style="overflow:hidden;height:33px;width:500px;border-width:1px 1px 1px 1px;border-style:dotted dotted dotted dotted;">  <table border="0" cellspacing="0" cellpadding="0">    <tr>      <td id="demo1"><img src="images/logo_1.gif"><img src="images/logo/flashempire.gif"><img src="images/logo.gif"><img src="images/logo/5dmedia.gif"><img src="images/logo/macromedia.gif"><img src="images/logo/sucaiw.gif"><img src="images/logo/blueieda.gif"><img src="images/logo/htmlcn.gif" border="0"></td>      <td id="demo2"> </td>    </tr>  </table></div><script language="javascript" type="text/javascript"><!--var demo = document.getElementById("demo");var demo1 = document.getElementById("demo1");var demo2 = document.getElementById("demo2");var speed=10;    //数值越大滚动速度越慢demo2.innerHTML = demo1.innerHTML;demo.scrollLeft = demo.scrollWidth;function Marquee(){    if(demo.scrollLeft<=0)        demo.scrollLeft+=demo2.offsetWidth    else{        demo.scrollLeft--    }}var MyMar = setInterval(Marquee,speed)demo.onmouseover = function(){clearInterval(MyMar)}demo.onmouseout = function(){MyMar = setInterval(Marquee,speed)}--></script>

你可能感兴趣的:(JavaScript,html,Blog,firefox)