jQuery实现透明度变化轮播效果

匆忙写的一个透明度变化的轮播效果,欢迎指出错误,感谢!!!

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>jQuery透明度变化轮播效果</title>
    <script type="text/javascript" src="../bootstrap-3.3.7/js/jquery2.0.js"></script>
    <style>
        * {
            font-family: 微软雅黑;
        }

        .container {
            width: 1140px;
            padding: 0 15px;
            margin: 0 auto;
        }

        #zz_carousel {
            width: 1140px;
            height: 500px;
            overflow: hidden;
            position: relative;
        }

        #zz_carousel:hover .arrow {
            display: block;
        }

        #zz_carousel .paging {
            position: absolute;
            bottom: 15px;
            left: 50%;
        }

        #zz_carousel .paging span {
            display: inline-block;
            width: 15px;
            height: 15px;
            border-radius: 50%;
            background-color: #eee;
            margin-left: 15px;
            cursor: pointer;
        }

        #zz_carousel .paging span.active {
            background-color: darkslategrey;
        }

        #zz_carousel .image_reel {
            position: absolute;
        }

        #zz_carousel .image_reel img {
            width: 1140px;
            height: 500px;
            display: none;
        }
        #zz_carousel .image_reel img:first-child{
            display: block;
        }
        #zz_carousel .next {
            position: absolute;
            top: 50%;
            margin-top: -50px;
            right: 0;
        }

        #zz_carousel .previous {
            position: absolute;
            top: 50%;
            margin-top: -50px;
            left: 0;
        }

        a {
            text-decoration: none;
            color: #fff;
        }

        #zz_carousel .arrow {
            font-size: 50px;
            display: none;
        }

        #zz_carousel .arrow:hover {
            background-color: #f0f3ef;
            color: #091b22;
        }
    </style>
</head>
<body>

<div class="container">
    <div class="carousel" id="zz_carousel">
        <!--图片容器,移动的元素-->
        <div class="image_reel">
            <a href="#"><img src="images/1.jpg" alt=""></a>
            <a href="#"><img src="images/2.jpg" alt=""></a>
            <a href="#"><img src="images/3.jpg" alt=""></a>
            <a href="#"><img src="images/4.jpg" alt=""></a>
            <a href="#"><img src="images/5.jpg" alt=""></a>
        </div>
        <!--图片下方的小圆点,js动态添加-->
        <div class="paging"></div>
        <!--左右控制按钮-->
        <div class="change">
            <sapn class="previous"><a href="#" class="arrow">&lt;</a></sapn>
            <span class="next"><a href="#" class="arrow">&gt;</a></span>
        </div>
    </div>
</div>
<script>
    $(function () {
        //1. 获取元素
        var $zz_carousel = $('#zz_carousel');
        var $imgs = $zz_carousel.find('.image_reel img');
        var $paging = $zz_carousel.find('.paging');
        var $previous =$zz_carousel.find('.previous');
        var $next =$zz_carousel.find('.next');

        //2. 添加小圆点
        var picIdx = 0;
        $imgs.each(function (index) {
            var $span = $('<span></span>');
            $span.idx = index;
            $span.appendTo($paging);
            $span.click(function () {
                $(this).addClass('active').siblings().removeClass('active');
                picIdx = $span.idx;
                $imgs.eq(picIdx).stop().fadeIn();
                $imgs.not($imgs.eq(picIdx)).fadeOut();
            });
        });
        //给paging设置margin-left 让它居中
        $paging.children().eq(0).addClass('active');
        $paging.css({
            marginLeft : -($paging.outerWidth() / 2)
        });
        //3. 左右按钮点击事件
        $previous.click(function () {
            if(picIdx == 0){
                picIdx = $imgs.length ;
            }
            picIdx --;
            $imgs.eq(picIdx).stop().fadeIn();
            $imgs.not($imgs.eq(picIdx)).fadeOut();
            $paging.children().eq(picIdx).addClass('active');
            $paging.children().not($paging.children().eq(picIdx)).removeClass('active');
        });
        $next.click(function () {
            if(picIdx == $imgs.length - 1){
                picIdx = -1;
            }
            picIdx ++;
            $imgs.eq(picIdx).stop().fadeIn();
            $imgs.not($imgs.eq(picIdx)).fadeOut();
            $paging.children().eq(picIdx).addClass('active');
            $paging.children().not($paging.children().eq(picIdx)).removeClass('active');
        });
        //4. 自动播放和鼠标移入移出事件
        var timer = setInterval(function () {
            $next.trigger('click');
        },3000);
        $zz_carousel.hover(function () {
            clearInterval(timer);
        },function () {
            clearInterval(timer);
            timer = setInterval(function () {
                $next.trigger('click');
            },3000);
        })
    });
</script>
</body>
</html>
  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值