Swiper实现间距轮播图特效代码

Swiper实现间距轮播图特效代码

一款基于swiper横向轮播,简单好用,兼容IE8浏览器,需要的朋友可以免费下载此特效。

使用方法
在页面引入相关CSS样式文件

1
2
<link rel="stylesheet" href="css/swiper.min.css">
<link rel="stylesheet" href="css/certify.css">

Javascript代码

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
var certifySwiper = new Swiper('#certify .swiper-container', {
    watchSlidesProgress: true,
    slidesPerView: 'auto',
    centeredSlides: true,
    loop: true,autoplay:true,
    loopedSlides: 5,
    autoplay: true,
    navigation: {
        nextEl: '.swiper-button-next',
        prevEl: '.swiper-button-prev',
    },
    pagination: {
        el: '.swiper-pagination',
        //clickable :true,
    },
    on: {
        progress: function(progress) {
            for (i = 0; i < this.slides.length; i++) {
                var slide = this.slides.eq(i);
                var slideProgress = this.slides[i].progress;
                modify = 1;
                if (Math.abs(slideProgress) > 1) {
                    modify = (Math.abs(slideProgress) - 1) * 0.3 + 1;
                }
                translate = slideProgress * modify * 260 + 'px';
                scale = 1 - Math.abs(slideProgress) / 5;
                zIndex = 999 - Math.abs(Math.round(10 * slideProgress));
                slide.transform('translateX(' + translate + ') scale(' + scale + ')');
                slide.css('zIndex', zIndex);
                slide.css('opacity', 1);
                if (Math.abs(slideProgress) > 3) {
                    slide.css('opacity', 0);
                }
            }
        },
        setTransition: function(transition) {
            for (var i = 0; i < this.slides.length; i++) {
                var slide = this.slides.eq(i)
                slide.transition(transition);
            }

        }
    }

})

HTML结构

1
2
3
4
5
6
7
8
9
10
11
12
13
14
<div id="certify">
<div class="swiper-container">
<div class="swiper-wrapper">
<div class="swiper-slide"><img src="images/certify01.png" /><p>Picture information 1</p></div>
<div class="swiper-slide"><img src="images/certify02.png" /><p>Picture information 2</p></div>
<div class="swiper-slide"><img src="images/certify03.png" /><p>Picture information 3</p></div>
<div class="swiper-slide"><img src="images/certify04.png" /><p>Picture information 4</p></div>
<div class="swiper-slide"><img src="images/certify05.png" /><p>Picture information 5</p></div>
</div>
</div>
<div class="swiper-pagination"></div>
<div class="swiper-button-prev"></div>
<div class="swiper-button-next"></div>
</div>
当前内容只有登录了才能查看,如果您已经注册,请登录
1

发表评论