zoukankan      html  css  js  c++  java
  • 简单通过js实现轮播图

    选取几张图片然后用HTML放入图片,CSS布局,js用setInterval设置时间延时 进行自动播放

    代码部分:

    HTML

    <!DOCTYPE html>
    <html lang="en">
    <head>
        <meta charset="UTF-8">
        <title>Title</title>
        <link rel="stylesheet" href="1111.css">
        <script src="1111.js"></script>
    </head>
    <body>
        <div id="lunbo" class="lunbo">
            <div class="lunbotu">
                <a href="">
                    <img src="img1.jpg" alt="">
                </a>
            </div>
            <div class="lunbotu">
                <a href="">
                    <img src="img2.jpg" alt="">
                </a>
            </div>
            <div class="lunbotu">
                <a href="">
                    <img src="img3.jpg" alt="">
                </a>
            </div>
        </div>
    </body>
    </html>

    CSS

    .lunbo img{
        width:410px ;
        height: 225px;
    }
    .lunbotu{
        position: absolute;
        left:310px;
        top:0;
        /*z-index: 2;*/
        display: none;
    }

    JS

    window.onload=function () {
        var lunboimg = document.getElementById('lunbo').getElementsByTagName('div');
        var n=0;
        function lunbofun() {
            for (var i=0;i<lunboimg.length;i++){
                lunboimg[i].style.display='none';
            }
            lunboimg[n].style.display='block';
        }
        function start(){
            n++;
            if (n>=lunboimg.length) {
                n=0;
            }
            lunbofun();
        }
        setInterval(start,3000);
    }

    显示效果:

    ╰︶﹉⋛⋋⊱⋋๑๑⋌⊰⋌⋚﹉︶╯
  • 相关阅读:
    jQuery火箭图标返回顶部代码
    类库引用EF
    Html.DropDownList
    MVC validation
    MVC @functions
    MVC 扩展方法特点
    Class 实现IDisposing方法
    MVC两个必懂核心
    Asp.net 服务器Application,Session,Cookie,ViewState和Cache区别
    sqlserver log
  • 原文地址:https://www.cnblogs.com/zhangcheng001/p/11001999.html
Copyright © 2011-2022 走看看