jQuery轮播图

jQ轮播图    jquery-1.8.3.js版

<!DOCTYPE html>
<html>
<head lang="en">
    <meta charset="UTF-8">
    <title></title>
    <style>
        *{
            margin: 0;
            padding: 0;
        }
        li{
            list-style: none;
        }
        a{
            text-decoration: none;
        }
        img{
            width: 200px;
            height: 150px;
        }
        .img{
            width: 20001px;
            position: absolute;
        }
        .img_item{
            float: left;
        }

         #lun{
            width: 200px;
            height: 150px;
            border: 1px solid saddlebrown;
            overflow: hidden;
            margin: 10px auto;
            position: relative;
        }

        .btn{
            position: absolute;
            top: 75px;
        }
        .next{
            right: 0;
        }
        .prev{
            left: 0;
        }

        .nav{
            position: absolute;
            /*border: 1px solid turquoise;*/
            left: 45px;
            bottom: 10px;
        }
        .nav_item{
            width: 20px;
            height: 20px;
            border-radius: 50%;
            display: inline-block;
            margin-left: 5px;
            background: white;
            text-align: center;
            line-height: 20px;
        }

        .nav:first-child{
            margin-left: 0;
        }

        .nav_item.active{
            background: rosybrown;
        } .nav_item{
           cursor: pointer;
        }

    </style>
    <script src="jquery-1.8.3.js"></script>
</head>
<body>
<div id="lun">

    <!--图-->
    <ul class="img">
        <li class="img_item"><a href="javascript:;"><img src="img/1.jpg" alt=""/></a></li>
        <li class="img_item"><a href="javascript:;"><img src="img/2.jpg" alt=""/></a></li>
        <li class="img_item"><a href="javascript:;"><img src="img/3.jpg" alt=""/></a></li>
        <li class="img_item"><a href="javascript:;"><img src="img/4.jpg" alt=""/></a></li>
        <li class="img_item"><a href="javascript:;"><img src="img/1.jpg" alt=""/></a></li>
    </ul>

    <!--下标-->
    <ul class="nav">
        <li class="nav_item active">1</li>
        <li class="nav_item">2</li>
        <li class="nav_item">3</li>
        <li class="nav_item">4</li>
    </ul>

    <!--左右键-->
    <button class="btn prev">&lt;</button>
    <button class="btn next">&gt;</button>
</div>

<script>

    var n=0;
    var size=$(".img_item").size();

    /*右键函数*/
    function ne(){
//        alert(1)
        n++;
//        console.log(n);
        dong();
        diandian();
    }
    /*左键函数*/
    function pr(){
//        alert(1)
        n--;
//        console.log(n);
        dong();
        diandian();
    }

/*左右键*/
    $(".next").click(ne);

    $(".prev").click(pr);

    /*鼠标移入停止 鼠标移出继续*/
    $("#
lun").hover(function(){
        clearInterval(time);
    },function(){
        time=setInterval(ne,1000);
    });

    /*自动轮播函数*/
    var time=setInterval(ne,1000);

    /*小圆点自动切换函数*/
    function diandian(){
        if(n==size-1){
            $(".nav_item").eq(0).addClass('active').siblings().removeClass('active');
        }

        else{
            $(".nav_item").eq(n).addClass('active').siblings().removeClass('active');
        }
    }

    /*运动函数*/

    function dong(){
        if(n==size){
            $(".img").css('left',0);
            n = 1;
        }
        if(n==-1){
            n=size-2;
        }

        $(".img").stop().animate({left:-n*200},500);

    }

    /*点击小圆点切换函数*/

    $('.nav_item').hover(function(){
//        alert(1);
        var index=$(this).index();
        n=index;
//        console.log(index);
        dong();
        $(".nav_item").eq(index).addClass('active').siblings().removeClass('active');
    });

</script>
</body>
</html>
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值