轮播图更新jquery版本

1.css代码

 * {
            margin: 0;
            padding: 0;
            list-style: none;
        }

        .slider {
            height: 340px;
            width: 790px;
            position: relative;
            overflow: hidden;
        }

        .slider ul>li {
            float: left;
            overflow: hidden;
        }

        .slider ul>li:first-child {
            display: block;
        }

        .arrow {
            display: none;
        }

        .slider:hover .arrow {
            display: block;
        }

        .arrow-left,
        .arrow-right {
            width: 30px;
            height: 60px;
            background-color: rgba(0, 0, 0, 0.1);
            position: absolute;
            top: 50%;
            margin-top: -30px;
            cursor: pointer;
            text-align: center;
            line-height: 60px;
            color: #fff;
            font-weight: 700;
            font-size: 30px;
        }

        .arrow-left:hover,
        .arrow-right:hover {
            background-color: rgba(0, 0, 0, .5);
        }

        .arrow-left {
            left: 0;
        }

        .arrow-right {
            right: 0;
        }
        ol{
            position: absolute;
            left: 50%;
            margin-left: -160px;
            bottom: 20px;
            line-height: 20px;
            text-align: center;
        }
        ol li{
            float: left;
            width: 30px;
            height: 30px;
            border-radius: 5px;
            background: #fff;
            border: 1px solid #ccc;
            margin-left: 10px;
            cursor: pointer;
            font-size: 14px;
            text-align: center;
            line-height: 30px;
        }
        .red{
            background: #4fcaff;
            color: #fff;
        }
        #myUl{
            width: 7110px;
        }

2.html代码

<div class="slider">
    <ul id="myUl">
        <li><a href="#"><img src="images/01.jpg" alt=""></a></li>
        <li><a href="#"><img src="images/02.jpg" alt=""></a></li>
        <li><a href="#"><img src="images/03.jpg" alt=""></a></li>
        <li><a href="#"><img src="images/04.jpg" alt=""></a></li>
        <li><a href="#"><img src="images/05.jpg" alt=""></a></li>
        <li><a href="#"><img src="images/06.jpg" alt=""></a></li>
        <li><a href="#"><img src="images/07.jpg" alt=""></a></li>
        <li><a href="#"><img src="images/08.jpg" alt=""></a></li>
        <li><a href="#"><img src="images/01.jpg" alt=""></a></li>
    </ul>
    <ol>
        <li class="red">1</li>
        <li>2</li>
        <li>3</li>
        <li>4</li>
        <li>5</li>
        <li>6</li>
        <li>7</li>
        <li>8</li>
    </ol>
    <!--箭头-->
    <div class="arrow">
        <span class="arrow-left">&lt;</span>
        <span class="arrow-right">&gt;</span>
    </div>

3.jquery代码

  var index = 0;
    var time = setInterval(move, 1500);
    var width = $(".slider").width();

    function move() {
        index++;
        $("#myUl").animate({marginLeft:-index*width },500);
        if( index == 8){
            //瞬间换成第一张图片
            index = 0;
            $("#myUl").animate({marginLeft:-index*width },0);
        }
        //设置小圆点
        $("ol li").eq(index).addClass("red").siblings().removeClass("red");
    }
    //移入移出
    $(".slider").mouseenter(function () {
        clearInterval(time);
    })
    $(".slider").mouseleave(function () {
        time = setInterval(move, 1500);
    })
    //点击左右按钮
    $(".arrow-left").click(function () {
        if(index == 0){
            index = 8;
            $("#myUl").animate({marginLeft: -index*width},0);
        }
        index--;
        $("#myUl").animate({marginLeft:-index*width },500);
        //设置小圆点
        $("ol li").eq(index).addClass("red").siblings().removeClass("red");
    })

    $(".arrow-right").click(move);

    //点击小圆点滑动到对应的图片
    $("ol li").mouseenter(function () {
        index = $(this).index();
        $("#myUl").animate({marginLeft:-index*width },500);
        //设置小圆点
        $("ol li").eq(index).addClass("red").siblings().removeClass("red");

    })

效果图
在这里插入图片描述
在使用jquery之前一定要引用jquery的相关js代码

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值