我上面的函数改自
<div id="demo" style="overflow:hidden;height:500px;width:120px; border:1px solid #dde5bc; overflow:hidden;float:left">
<div id=demo1> 
<img src="images/js01.gif" width="120" height="120">
<img src="images/js02.gif" width="120" height="120"><img src="images/js03.gif" width="120" height="120">
<img src="images/js04.gif" width="120" height="120">
<img src="images/js05.gif" width="120" height="120">
<img src="images/js06.gif" width="120" height="120">
<img src="images/js07.gif" width="120" height="120">
<img src="images/js08.gif" width="120" height="120">
<img src="images/js09.gif" width="120" height="120"></div>
<div id=demo2></div>
</div>
<script>
var speed=40
var demo=document.getElementById("demo");
var demo2=document.getElementById("demo2");
var demo1=document.getElementById("demo1");
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>我就是想用一个函数来实现连续滚动,哪位如果能够把这个改成函数也可以!

解决方案 »

  1.   

    <div id="demo" style="overflow:hidden;height:500px;width:120px; border:1px solid #dde5bc; overflow:hidden;float:left">
    <div id=demo1> 
    <img src="images/js01.gif" width="120" height="120">
    <img src="images/js02.gif" width="120" height="120"><img src="images/js03.gif" width="120" height="120">
    <img src="images/js04.gif" width="120" height="120">
    <img src="images/js05.gif" width="120" height="120">
    <img src="images/js06.gif" width="120" height="120">
    <img src="images/js07.gif" width="120" height="120">
    <img src="images/js08.gif" width="120" height="120">
    <img src="images/js09.gif" width="120" height="120"></div>
    <div id=demo2></div>
    </div>
    <script>
    var speed=40
    var demo=document.getElementById("demo");
    var demo2=document.getElementById("demo2");
    var demo1=document.getElementById("demo1");
    demo2.innerHTML=demo1.innerHTML
    function Marquee(){
    if(demo2.offsetTop-demo.scrollTop<=0)
    demo.scrollTop-=demo1.offsetHeight
    else{
    demo.scrollTop++
    }
    }
    var MyMar=setInterval(Marquee,speed)
    clearInterval(MyMar)
    demo.onmouseover=function() {clearInterval(MyMar)}
    demo.onmouseout=function() {MyMar=setInterval(Marquee,speed)}
    function bb()
    {
    MyMar=setInterval(Marquee,speed)
    }
    </script>
    <a href="javascript:bb()">滚动</a>