纯js轮播


<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>轮播</title>
    <style>
        *{margin: 0;
            padding:0;}
        .wrap{
            position: relative;
            width: 500px;
            height: 200px;
            background: #ccc;
            margin:20px auto;
        }
        .pics,.pics li,.pics li img{
            width: 100%;
            height: 100%;
        }
        .pics li{
            position: absolute;
        }
        .btn{
            position: absolute;
            top:70px;
            height: 60px;
            width: 40px;
            background: rgba(0,0,0,0.5);
            color: #fff;
            text-align: center;
            line-height: 60px;
            font-size: 30px;
            font-weight: lighter;
            cursor: pointer;
            z-index: 2;
        }
        .btn:hover{
            background:rgba(0,0,0,0.8);
        }
        .btnr{
            right: 0;
        }
        ul{list-style:none;}
        .pots{
            position: absolute;
            left:166px;
            bottom: 10px;
        }
        .pots div{
            width: 20px;
            height: 20px;
            background-color: #5388e8;
            float: left;
            text-align: center;
            line-height: 20px;
            color: #fff;
            margin-right: 5px;
            border-radius: 50%;
            cursor: pointer;
        }
        .pots div.active{background-color: #ff0000;}
    </style>
</head>
<body>
<div class="wrap">
    <ul class="pics">
        <li><img src="img/1.png" alt=""></li>
        <li><img src="img/2.png" alt=""></li>
        <li><img src="img/3.png" alt=""></li>
        <li><img src="img/4.png" alt=""></li>
        <li><img src="img/5.png" alt=""></li>
        <li><img src="img/6.png" alt=""></li>
        <li><img src="img/0.png" alt=""></li>
    </ul>
    <div class="pots">
        <div class="active">1</div>
        <div>2</div>
        <div>3</div>
        <div>4</div>
        <div>5</div>
        <div>6</div>
        <div>7</div>
    </div>
    <div class="btn btnl"><</div>
    <div class="btn btnr">></div>
</div>
<script src="jquery-1.4.2.min.js"></script>
<script>
var $li=$(".pics li");
var count=0;
var timer;
$(function(){
    $li.eq(0).show().siblings().hide();
    ShowTime();
    $(".pots div").hover(function(){
        clearInterval(timer);
        count = $(this).index();
        Show();
    },function(){
        ShowTime();
    });


    $(".btnl").click(function(){
        clearInterval(timer);
        count--;
        if(count == -1){
            count = $li.length;
        }
        Show();
    });
    $(".btnr").click(function(){
        clearInterval(timer);
        count++;
        if(count == $li.length){
            count = 0;
        }
        Show();
    });
});
function Show(){
    $li.eq(count).fadeIn(300).siblings().hide();
    $(".pots div").eq(count).addClass("active").siblings().removeClass("active");
}
function ShowTime(){
    timer = setInterval(function(){
        count++;
        Show();
    },2000);
}
</script>
</body>
</html>
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值