依赖jQuery的无缝切换

<!DOCTYPE html>
<html>
    <head>
        <meta charset="UTF-8">
        <title></title>
        <style>
            *{
                padding: 0;
                margin: 0;
                list-style: none;
            }
            .box{
                width: 300px;
                height: 200px;
                margin: 100px auto;
                overflow: hidden;
                position: relative;
            }
            .box .list{
                height: 200px;
                width: 2100px;
                position: absolute;
            }
            .box .list img{
                width: 300px;
                height: 200px;
                border: none;
                float: left;
            }
            .btn{
                position: absolute;
                bottom: 10px;
                left: 50%;
                margin-left: -75px;
                height: 15px;
                width: 150px;
                
            }
            .btn li{
                font: 12px/15px "微软雅黑";
                color: #fff;
                float: left;
                width: 15px;
                height: 15px;
                text-align: center;
                margin-left: 10px;
                border-radius: 50%;
                background: rgba(0,0,0,0.6);
                cursor: pointer;
            }
            .btn .on{
                background: orange;
            }
            a{
                display: block;
                width: 30px;
                height: 30px;
                position: absolute;
                top: 50%;
                margin-top: -15px;
                font: 14px/30px "微软雅黑";
                color: #fff;
                text-align: center;
                text-decoration: none;
            }
            .box .prve{
                left: 0;
            }
            .box .next{
                right: 0;
            }
        </style>
        <script src="http://libs.baidu.com/jquery/2.0.0/jquery.min.js"></script>
    </head>
    <body>
        <div class="box">
            <div class="list" style="left: 0px;">
                <img src="images/4.jpg" alt="" />
                <img src="images/0.jpg" alt="" />
                <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/0.jpg" alt="" />
            </div>
            <ul class="btn">
                <li class="on">1</li>
                <li>2</li>
                <li>3</li>
                <li>4</li>
                <li>5</li>
            </ul>
            <a class="prve" href="javascript:;">上</a>
            <a class="next" href="javascript:;">下</a>
        </div>
    </body>
    <script type="text/javascript">
        var list = $('.list');
        var box = $('.box');
        var btn = $('.btn');
        var bs = btn.find('li');
        var n = 0;
        var prve = $('.prve');
        var next = $('.next');
        //上一页
        prve.click(function(){
            n--;
            if(n<1){
                n=5;
                bs.eq(5).addClass('on').siblings().removeClass('on');
                list.css({
                    marginLeft: -1800
                },200);
            }
            main(n,n);
        });
        //下一页,用于改变图片和显示按钮
        next.click(function(){
            move();
        });
        //主函数
        function main(e,x){
            list.stop().animate({
                marginLeft:-e*300
            },200);
            bs.eq(x-1).addClass('on').siblings().removeClass('on');
        }        
        timer = setInterval(move,2000);
        //鼠标移入移出关闭定时器,开启定时器
        box.hover(function(){
            clearInterval(timer);
        },function(){
            timer = setInterval(move,2000);
        });
        //点击按钮
        btn.on('click','li',function(){
            var index = $(this).index();
            if(index==5){
                bs.eq(6).addClass('on').siblings().removeClass('on');
            }else{
                bs.eq(index).addClass('on').siblings().removeClass('on');
            }    
            main(index+1);    
            n = index;
        });
        //计算
        function move(){
            n++;
            if(n == 6){        
                bs.eq(0).addClass('on').siblings().removeClass('on');    
            }
            if(n>6){
                n =2;
                list.css({
                    marginLeft: -300
                },200);
                bs.eq(1).addClass('on').siblings().removeClass('on');
            }
            main(n,n);
        }
    </script>
</html>
 

转载于:https://my.oschina.net/u/2879089/blog/841964

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值