zoukankan      html  css  js  c++  java
  • 无缝滚动+定时器

    <html>
        <head>
            <meta charset="UTF-8">
                <meta name="viewport" content="width=device-width,initial-scale=1,minimum-scale=1,maximum-scale=1,user-scalable=no" />
            <title></title>
            <style>
                #demo {
     /*background: #FFF;*/
     overflow:hidden;
     border: 1px dashed #CCC;
      830px;//width=100%;
     height:150px;
     }
     #demo img {
     border: 3px solid #F2F2F2;
     }
     #indemo {
     float: left;
      400%;//越大越好
     }
     #demo1 {
     float: left;
     }
     #demo2 {
     float: left;
     }
     img{
         float: left;
          320px;
         height: 150px;
     }
    </style>
        </head>
        <body>
            
    <div id="demo">
    <div id="indemo">
    <div id="demo1">
    <a href="#"><img src="img/1106628.jpg" border="0" /></a>
    <a href="#"><img src="img/1106914.jpg" border="0" /></a>
    <a href=""><img src="img/1111588.jpg"/>
    </a>
    <a href=""><img src="img/1113230.jpg"/></a>
    </div>
    <div id="demo2"></div>
    </div>
    </div>
        </body>
        <script>    
    var speed=10;
    var tab=document.getElementById("demo");
    var tab1=document.getElementById("demo1");
    var tab2=document.getElementById("demo2");
    tab2.innerHTML=tab1.innerHTML;

    function Marquee(){
    if(tab2.offsetWidth-tab.scrollLeft==0){
    tab.scrollLeft=0;
    }
    else{
    // alert(tab2.offsetWidth);alert(tab.scrollLeft)
     tab.scrollLeft++;
     
     }
    }

    var MyMar=setInterval(Marquee,speed);


    //鼠标事件

    tab.onmouseover=function() {clearInterval(MyMar)};
    tab.onmouseout=function() {MyMar=setInterval
    (Marquee,speed)};
    </script>

    </html>

    注释:

    tab2.offsetWidth:是指整个demo2的宽度;

    tab.scrollLeft:指对象(#demo)的左边界和窗口中目前可见内容(#demo和#demo2)的最左端的距离;

  • 相关阅读:
    bloom filter
    【转】单实例
    Log Structured Merge Trees(LSM) 原理
    【转】南网成立始末
    变电站综合自动化系统
    bsp tree
    Private Bytes,Working Set,Virtual Size的区别
    kdtree
    asp.net下载文件几种方式
    C# FTP操作
  • 原文地址:https://www.cnblogs.com/impossible1994727/p/6800746.html
Copyright © 2011-2022 走看看