美文网首页
JS无缝滚动,走马灯

JS无缝滚动,走马灯

作者: 武汉前端任金杰 | 来源:发表于2020-11-13 18: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>

    相关文章

      网友评论

          本文标题:JS无缝滚动,走马灯

          本文链接:https://www.haomeiwen.com/subject/fmrbbktx.html