zoukankan      html  css  js  c++  java
  • 图片切换

    <!DOCTYPE html>
    <html lang="en">
    <head>
    <meta charset="UTF-8">
    <title>Document</title>
    <style>
    *{
        margin: 0;
        padding: 0;
    }
    body{
        background-color: #eeeeee;
    }
    .warp{
        position: relative;
        width: 500px;
        height: 300px;
        margin: 50px auto;
        overflow: hidden;
    }
    .btns{
        position: absolute;
        right: 30px;
        bottom: 30px;
        z-index: 2;
    }
    .btns li{
        display: block;
        float: left;
        width: 14px;
        height: 14px;
        background-color: #ffffff;
        border-radius: 7px;
        margin-left: 5px;
        font-size: 12px;
        text-align: center;
        line-height: 14px;
        color: red;
        cursor: pointer;
    }
    .btns li.active{
        background-color: green;
    }
    .box{
        width: 1500px;
        height: 300px;
        position: absolute;
        left: 0;
        top: 0;
    }
    .box li{
        display: block;
        width: 500px;
        height: 300px;
        float: left;
    }
    .box li.no1{background-color: black;}
    .box li.no2{background-color: orange;}
    .box li.no3{background-color: pink;}
    </style>
    </head>
    <body>
    <div class="warp" id="warp">
        <ul id="btns" class="btns">
            <li class="active">1</li>
            <li>2</li>
            <li>3</li>
        </ul>
        <ul class="box" id="box">
            <li class="no1">1</li>
            <li class="no2">2</li>
            <li class="no3">3</li>
        </ul>
    </div>
    <script src="js/jQuery-v1.8.3.js"></script>
    <script>
    $(function () {
        var btns = $('#btns li'),
            box = $('#box'),
            warp = $('#warp'),
            w = 500,
            iNow = 0.
            timer = null;
    
        function autoMove() {
            iNow++;
            if (iNow === btns.length) {
                iNow = 0;
            }
            btns.eq(iNow).addClass('active').siblings().removeClass('active');
            box.stop().animate({left : -w * iNow});
        }
    
        timer = setInterval(autoMove, 1000);
    
        btns.on({
            'mouseover' : function () {
                clearInterval(timer);
                var my = $(this),
                    i = my.index();
                iNow = i-1;
                autoMove();
            }
        });
    
        warp.on({
            'mouseover' : function () {
                clearInterval(timer);
            },
            'mouseout' : function () {
                timer = setInterval(autoMove, 1000);
            }
        });
        
    });
    </script>
    </body>
    </html>
    高否?富否?帅否? 否? 滚去学习!
  • 相关阅读:
    WordPress插入图片无法居中的解决方法
    wordpress文章显示同一分类下的上一篇下一篇
    git4
    git3
    git2
    git1
    百度地图vue版本标记点拖拽事件传参问题
    postcss-plugin-px2rem的使用
    保留小数位toFixed()方法的怪异表现
    大公司是怎样开发和部署前端代码(转张云龙大神的回答)
  • 原文地址:https://www.cnblogs.com/baixc/p/4177193.html
Copyright © 2011-2022 走看看