zoukankan      html  css  js  c++  java
  • 图片轮播

    <!DOCTYPE html>
    <html lang="en">
    <head>
    <meta charset="UTF-8">
    <title></title>
    <style type="text/css">
    .container{
    position: relative;
    }
    .container > img,
    .container .toolbar{
    position: absolute;
    }
    .container > img{
    left: 0;
    top: 0;
    }
    .container .toolbar{
    top: 430px;
    left: 150px;
    z-index: 100;
    }
    .container .toolbar a{
    display: inline-block;
    20px;
    height: 20px;
    background-color: blue;
    color: #ffffff;
    text-align: center;
    line-height: 20px;
    text-decoration: none;

    }
    .container .toolbar a.curr,
    .container .toolbar a:hover{
    background-color: yellow;
    color: #000;
    }
    </style>
    </head>
    <body>
    <div class="container">
    <img src="images/1.jpg" alt=""/>
    <img src="images/2.jpg" alt=""/>
    <img src="images/3.jpg" alt=""/>
    <img src="images/4.jpg" alt=""/>
    <img src="images/5.jpg" alt=""/>
    <img src="images/6.jpg" alt=""/>
    <div class="toolbar">
    <a href="javascript:void(0);" class="curr" onmouseover="showImg(0)" onmouseout="showImg('start')" >1</a>
    <a href="javascript:void(0);" onmouseover="showImg(1)" onmouseout="showImg('start')" >2</a>
    <a href="javascript:void(0);" onmouseover="showImg(2)" onmouseout="showImg('start')" >3</a>
    <a href="javascript:void(0);" onmouseover="showImg(3)" onmouseout="showImg('start')" >4</a>
    <a href="javascript:void(0);" onmouseover="showImg(4)" onmouseout="showImg('start')" >5</a>
    <a href="javascript:void(0);" onmouseover="showImg(5)" onmouseout="showImg('start')" >6</a>
    </div>
    </div>
    </body>

    <script type="text/javascript">

    var interval;
    //当前图片的索引
    var index = 0;
    var imgs = document.querySelectorAll(".container > img");
    var aes = document.querySelectorAll(".container > .toolbar > a");

    function showImg(num){

    if(num){
    if(typeof num == "number" && num>=0 && num<aes.length){
    index = num;
    clearInterval(interval);
    }

    if(num == 'start'){
    interval = setInterval(showImg,2000);
    return ;
    }

    }


    //得到图片
    for(var i=0;i<imgs.length;i++){
    //如果是当前要显示的图片 则设置z-index为最大 否则 设置为数组下标+1
    if(i == index){
    imgs[i].style.zIndex = 99;
    aes[i].className = "curr";
    }else{
    imgs[i].style.zIndex = (i+1);
    aes[i].className = " ";
    }
    }

    if(index > imgs.length-1){
    index = 0;
    }else{
    index++;
    }
    }

    interval = setInterval(showImg,2000);
    showImg();
    </script>
    </html>

  • 相关阅读:
    Search Insert Position(二分查找)
    c++基础题
    Divide Two Integers(模拟计算机除法)
    Swap Nodes in Pairs(链表操作)
    Letter Combinations of a Phone Number(带for循环的DFS,组合问题,递归总结)
    进程和程序的区别
    Add Two Numbers(链表)
    Longest Substring Without Repeating Characters
    02.友盟项目--原始日志数据生成
    01.友盟项目--nginx服务器配置
  • 原文地址:https://www.cnblogs.com/hwgok/p/5754904.html
Copyright © 2011-2022 走看看