JS无缝滚动,走马灯

2020-11-13  本文已影响0人  武汉前端任金杰

<!DOCTYPE html>

<html lang="en">

<head>

    <meta charset="UTF-8">

    <meta name="viewport" content="width=device-width, initial-scale=1.0">

    <title>无缝滚动</title>

    <style type="text/css">

    img{

    border:0;

    height:100px; width:150px;

    }

    td img{

    margin:0 10px;

    }

    </style>

    </head>

    <body>

    <!-- 纵向向无缝滚动-->

    <div id="demo" style="overflow:hidden;height:350px;width:200px">

    <div id="demo1">

    <a href="#" target="_blank"><img src="">1</a><p>

    <a href="#" target="_blank"><img src="">2</a><p>

    <a href="#" target="_blank"><img src="">3</a><p>

    <a href="#" target="_blank"><img src="">4</a><p>

    </div>

    <div id="demo2">

    </div>

    </div>

    <script>

    var speed=30;

    var demo2=document.getElementById("demo2");

    var demo1=document.getElementById("demo1");

    var demo=document.getElementById("demo");

    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>

    </body>

</html>

上一篇下一篇

猜你喜欢

热点阅读