前端开发自动轮播图

前端移动开发能做什么的|web前端开发案例书籍推荐|前端开发包就业

html 代码

<!DOCTYPE html>
<head>
    <meta charset=”utf-8″>
    <meta http-equiv=”X-UA-Compatible” content=”IE=edge,chrome=1″>
    <title>软件前端开发需要懂什么:Examples</title>
    <meta name=”description” content=””>
    <meta name=”keywords” content=””>
    <link href=”” rel=”stylesheet”>
    <style>
        * {
            margin: 0px;
            padding: 0px;
        }
        li {
            list-style: none;
        }
        a {
            text-decoration: none;
            color: white;
        }
        #banner {
            width: 600px;
            margin: 50px auto;
            position: relative;
        }
        #pic {
            width: 600px;
            height: 400px;
            border: 1px solid skyblue;
            position: relative;
        }
        #pic img {
            display: none;
            width: 600px;
            height: 400px;
            position: absolute;
            top: 0px;
            left: 0px;
        }
        #pic .on {
            display: block;
        }
        #btn .item {
            display: block;
            width: 40px;
            height: 40px;
            background: rgba(0, 0, 0, .2);
            position: absolute;
            top: 50%;
            margin-top: -20px;
            left: 0px;
            font-size: 20px;
            font-weight: bold;
            color: white;
            line-height: 40px;
            text-align: center;
            cursor: pointer;
            transition: all 0.3s ease-in;
        }
        #btn #next {
            right: 0px;
            left: auto;
        }
        #prve:hover {
            width: 60px;
            height: 45px;
            line-height: 45px;
            background: rgba(0, 0, 0, .5);
            font-size: 28px;
            margin-top: -22.5px;
        }
        #next:hover {
            width: 60px;
            height: 45px;
            line-height: 45px;
            background: rgba(0, 0, 0, .5);
            font-size: 28px;
            margin-top: -22.5px;
        }
        #text {
            width: 100%;
            position: absolute;
            top: 0px;
            left: 0px;
            background: rgba(0, 0, 0, .5);
            height: 35px;
            line-height: 35px;
            text-align: center;
            color: white;
        }
        #tab {
            width: 72px;
            position: absolute;
            bottom: 10px;
            left: 50%;
            margin-left: -30px;
        }
        #tab ul li {
            margin: 0px 3px;
            height: 12px;
            width: 12px;
            border-radius: 50%;
            background: white;
            float: left;
            cursor: pointer;
        }
        #tab .on {
            background: #f60;
        }
    </style>
</head>
<body>
    <div id=”banner”>
        <div id=”pic”>
            <img src=”1.jpg” alt=”” class=”on”>
            <img src=”2.jpg” alt=””>
            <img src=”3.jpg” alt=””>
            <img src=”4.jpg” alt=””>
        </div>
        <div id=”btn”>
            <span id=”prve” class=”item”>&lt;</span>
            <span id=”next” class=”item”>&gt;</span>
        </div>
        <p id=”text”>
            <span id=”txt”>1</span>/4</p>
        <div id=”tab”>
            <ul>
                <li class=”on”></li>
                <li></li>
                <li></li>
                <li></li>
            </ul>
        </div>
    </div>
    <script>
        var oimg = document.querySelectorAll(“#pic img”);
        var oli = document.querySelectorAll(“#banner #tab li”);
        var prve = document.getElementById(“prve”);
        var next = document.getElementById(“next”);
        var banner = document.getElementById(“banner”);
        var txt = document.getElementById(“txt”);
        var length = oimg.length;
        var index = 0;
        var timer = null;
        for (var i = 0; i < length; i++) {
            oli[i].goudan = i
            oli[i].onclick = function () {
                for (var j = 0; j < length; j++) {
                    oimg[j].className = “”;
                    oli[j].className = “”;
                }
                this.className = “on”;
                oimg[this.goudan].className = “on”;
                txt.innerHTML = this.goudan + 1;
                index = this.goudan;
            };
        }
        next.onclick = function () {
            index++;
            index %= length;
            for (var i = 0; i < length; i++) {
                oimg[i].className = “”;
                oli[i].className = “”;
            }
            oimg[index].className = “on”;
            oli[index].className = “on”;
            txt.innerHTML = index + 1;
        };
        prve.onclick = function () {
            index–;
            if (index < 0) index = length – 1;
            for (var i = 0; i < length; i++) {
                oimg[i].className = “”;
                oli[i].className = “”;
            }
            oimg[index].className = “on”;
            oli[index].className = “on”;
            txt.innerHTML = index + 1;
        }
        banner.onmouseover = function () {
            clearInterval(timer);
        }
        banner.onmouseout = function () {
            timer = setInterval(auto, 1500);
        }
        timer = setInterval(auto, 1500);
        function auto() {
            index++;
            index %= length;
            for (var i = 0; i < length; i++) {
                oimg[i].className = “”;
                oli[i].className = “”;
            }
            oimg[index].className = “on”;
            oli[index].className = “on”;
            txt.innerHTML = index + 1;
        }
    </script>
</body>
</html>

郑州前端开发工资|郑州前端开发工资|前端开发中的代码优化

» 本文来自:前端开发者 » 《前端开发自动轮播图》
» 本文链接地址:https://www.rokub.com/4202.html
» 您也可以订阅本站:https://www.rokub.com
赞(0)
64K

评论 抢沙发

评论前必须登录!