轮播图

<script src="js/jquery-1.8.3.min.js"></script>

<style>

*{

  margin: 0;

  padding: 0;

}

ul,li{

    list-style: none;

}

.box{

    width:800px;

    height: 500px;

    margin: 0 auto;

    position: relative;

    overflow: hidden;

}

.tu{

    height: 500px;

}

.tu li{

    float: left;

    width: 800px;

    height: 500px;

    background-size: cover;

}

.tu1{

    background: url(img/banner1.jpg) no-repeat 0 0;

}

.tu2{

    background: url(img/banner2.jpg) no-repeat 0 0;

}

.tu3{

    background :url(img/banner3.jpg) no-repeat 0 0;

}

.tu4{

    background: url(img/banner4.jpg) no-repeat 0 0;

}

.tu5{

    background: url(img/yh07.jpg) no-repeat 0 0;

}

.tu7{

    background: url(img/banner1.jpg) no-repeat 0 0;

}

.le,.re{

    width: 22px;

    height: 40px;

    position: absolute;

    top: 50%;

    margin-top: -20px;

}

.le{

    left: 50px;

    background: url(img/left.png) no-repeat 0 0;

}

.re{

    right: 50px;

    background: url(img/right.png) no-repeat 0 0;

}

.btn{

    width: 300px;

    position: absolute;

    bottom: 20px;

    left: 50%;

    margin-left: -150px;

}

.btn li{

    float: left;

    width: 30px;

    height: 6px;

    margin: 0 10px;

    background-color: aquamarine;

}

</style>

<body>

    <div class="box">

        <ul class="tu">

            <li class="tu1"></li>

            <li class="tu2"></li>

            <li class="tu3"></li>

            <li class="tu4"></li>

            <li class="tu5"></li>

            <li class="tu7"></li>

        </ul>

        <div class="le"></div>

        <div class="re"></div>

        <ul class="btn">

            <li></li>

            <li></li>

            <li></li>

            <li></li>

            <li></li>

            <li></li>

        </ul>

    </div>

</body>

<script>

$(function(){

    $(".tu ul li:first").clone(true).appendTo($('.tu ul'));

    $(".btn li:first").css({backgroundColor:"green"});

    $(".tu").width($(".tu li").length*800);

    var n=0;

    //右边点击

    $(".re").click(function(){

        n++;

        if(n>5){

            n=1;

            $(".tu").css({marginLeft:0});

        }

        changeBtn(n==6?0:n);

                $('.tu').stop(true,true).animate({marginLeft:-800*n},1000);

    })

    //左边点击

    $(".le").click(function(){

        n--;

        if(n<0){

            n=5;

            $(".tu").css({marginLeft:-800*6});

        }

        changeBtn(n);

        $(".tu").stop(true,true).animate({marginLeft:-800*n},1000)

    })

    //点

    function changeBtn(index){

        $(".btn li").eq(index).css({backgroundColor:"green"}).siblings().css({backgroundColor:"aquamarine"})

    }


    $(".btn li").click(function(){

        n=$(this).index();

        changeBtn($(this).index());

        $(".tu").animate({marginLeft:-800*$(this).index()},1000);

    })

})

</script>

©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容