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>

  • 相关阅读:
    如何:使用向导来处理项目模板 【转载】
    .NET : 如何在生成XML文档时绑定样式表
    如何在生产环境部署K2的流程
    SQL Server 数据库文档生成工具开源项目【合作邀请】
    新的纪元
    SharePoint : 谁说WSS不支持审核
    C++ : 类型的别名和对象的别名
    C++: 引用和地址运算符
    Infopath : 如何通过代码复制格式文本框的值
    正确地使用投影仪和移动硬盘
  • 原文地址:https://www.cnblogs.com/hwgok/p/5754904.html
Copyright © 2011-2022 走看看