zoukankan      html  css  js  c++  java
  • 【怪咖】------简单的轮播图------

    <!DOCTYPE html>
    <html>
      <head>
        <meta charset="UTF-8">
        <title></title>
        <style type="text/css">
          *{
            margin: 0;
            padding: 0;
           }
          #cont{
            position: absolute;
            margin-left: 40%;
            margin-top: 40px;
          }
            #cont p:nth-of-type(1){
             20px;
            height: 30px;
            background: gray;
            position: absolute;
            left:0;
            top:50%;
            font-size: 14px;
            line-height: 30px;
            text-align: center;
            display: none;
          }
          #cont p:nth-of-type(2){
           20px;
          height: 30px;
          background: gray;
          position: absolute;
          right:0;
          top:50%;
          font-size: 14px;
          line-height: 30px;
          text-align: center;
          display: none;
         }  
        </style>
      </head>
      <body>
        <div class="container">
          <div id='cont'>
            <p id='btn'><</p>
            <img id='round' src='img/2.jpg'>
            <p id='sub'>></p>
          </div>
        </div>
        <script type="text/javascript">
          //记录当前下标
          var index = 0;
          //创建数组
          var arr = new Array("2.jpg","3.jpg","4.jpg","5.jpg","6.jpg");
          //获取左右按键按钮
          var oBtn = document.getElementById('btn');
          var oSub = document.getElementById('sub');
          var oCont = document.getElementById('cont');
          //点击事件
          oBtn.onclick = function(){
          var Img =document.getElementById('round');
          if(index == arr.length - 1){
            index = 0;
          }else{
            index ++;
           }
          Img.src = 'img/' + arr[index];
          }
          oSub.onclick = function(){
            var Img =document.getElementById('round');
            if(index == arr.length - 1){
              index = 0;
            }else{
              index ++;
            }
            Img.src = 'img/' + arr[index];

          }
          //自动轮播
          var timer = null;
          function autoPlay(){
            timer = setInterval(function(){
              var Img =document.getElementById('round');
              if(index == arr.length - 1){
                index = 0;
              }else{
                index ++;
              }
              Img.src = 'img/' + arr[index];

             },1500);
            }

            //移入事件
            oCont.onmouseenter = function(){
              oBtn.style.display = 'block';
              oSub.style.display = 'block';
              //移入停止自动轮播
              clearInterval(timer);
            }
            //移除事件
            oCont.onmouseleave = function(){
              oBtn.style.display = 'none';
              oSub.style.display = 'none';
              //移出开启自动轮播
              autoPlay();

            }
        </script>
      </body>
    </html>

  • 相关阅读:
    Spring Boot确保Web应用安全(登陆认证)
    ubuntu kylin 18.04安装docker笔记
    Spring Boot项目中MyBatis连接DB2和MySQL数据库返回结果中一些字符消失——debug笔记
    node.js运行内存堆溢出的解决办法
    [转]Maven项目读取src.main.resources下的文件
    Linux下切换用户根目录的指令
    Example config file /etc/vsftpd.conf
    一个可以让vsftpd启动系统用户登陆ftp的例子
    [转]将西部数据 My Passport Wireless 移动存储连接到任何支持的云存储上
    Java连接阿里云HBase示例
  • 原文地址:https://www.cnblogs.com/xiaoyushuai/p/10231937.html
Copyright © 2011-2022 走看看