分享好友 教程首页 教程搜索 频道列表

swiper轮播(中间大两边小滚动有过渡效果)

2022-01-19 18:137180
+关注29
核心提示:效果用代码测试

示例1:

CSS

//css
// @charset "utf-8";
#certify {
    position: relative;
    width: 471px;
    height: 441px;
    margin-left: 35px;
    // width: 1200px;
    // margin: 0 auto
}
 
#certify .swiper-container {
    padding-top: 40px
}
 
#certify .swiper-slide {
    width: 228px;
    height: 378px;
    overflow: hidden;
    background: #fff;
    box-shadow: 0 8px 30px #ddd
}
 
#certify .swiper-slide img {
    width: 100%;
    display: block
}
 
#certify .swiper-slide p {
    line-height: 98px;
    padding-top: 0;
    text-align: center;
    color: #636363;
    font-size: 1.1em;
    margin: 0
}
 
 
 
#certify1 {
    float: right;
    width: 4.5rem;
    height: auto;
    position: relative;
    top: 0.72rem;
}
 
 
 
#certify1 .swiper-slide {
    width:4rem;
    height:auto;
    overflow: hidden;
    background: #fff;
    box-shadow: 0 8px 30px #ddd
}
 
#certify1 .swiper-slide img {
    width: 100%;
    display: block
}


html

<div id="certify1">
<div class="swiper-container">
<div class="swiper-wrapper">
<!-- <div class="swiper-slide"><img src="img/pc/pc_photo_home_Features_1.png" /></div>
<div class="swiper-slide"><img src="img/pc/pc_photo_home_Features_2.png" /></div>
<div class="swiper-slide"><img src="img/pc/pc_photo_home_Features_3.png" /></div>
<div class="swiper-slide"><img src="img/pc/pc_photo_home_Features_4.png" /></div> 
<div class="swiper-slide"><img src="img/pc/pc_photo_home_Features_5.png" /></div> -->

<% section2Info.block2.img.forEach(function(item){%>
<div class="swiper-slide"><img src="<%=item %>" /> </div>
<% }) %>
</div>
</div>
</div>


JS

//pc 的轮播
var certifySwiper = new Swiper('#certify .swiper-container', {
    watchSlidesProgress: true,
    slidesPerView: 'auto',
    centeredSlides: true,
    loop: true,
    // autoplay: true,
    //这样写是为了防止手动滚动之后 自动滚动就失效了
    autoplay: {
        disableOnInteraction: false,
        delay:2000,
    },
    loopedSlides: 5,
    navigation: {
        nextEl: '.swiper-button-next',
        prevEl: '.swiper-button-prev',
    },
    pagination: {
        el: '.swiper-pagination',
        //clickable :true,
    },
    on: {
        progress: function (progress) {
            for (var i = 0; i < this.slides.length; i++) {
                var slide = this.slides.eq(i);
                var slideProgress = this.slides[i].progress;
 
                var modify = 1;
                if (Math.abs(slideProgress) > 1) {
                    modify = (Math.abs(slideProgress) - 1) * 0.1 + 1;
                }
 
                // var translate = slideProgress * modify * 114 + 'px';
                var translate = slideProgress * modify * 150 + 'px';
                var scale = 1 - Math.abs(slideProgress) / 7;
                var 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);
            }
 
        }
    }
 
})


实例2:

HTML

<div id="certify1">
    <div class="swiper-container">
        <div class="swiper-wrapper">
            <!-- <div class="swiper-slide"><img src="img/pc/pc_photo_home_Features_1.png" /></div>
            <div class="swiper-slide"><img src="img/pc/pc_photo_home_Features_2.png" /></div>
            <div class="swiper-slide"><img src="img/pc/pc_photo_home_Features_3.png" /></div>
            <div class="swiper-slide"><img src="img/pc/pc_photo_home_Features_4.png" /></div> 
            <div class="swiper-slide"><img src="img/pc/pc_photo_home_Features_5.png" /></div> -->

            <% section2Info.block2.img.forEach(function(item){%>
            <div class="swiper-slide"><img src="<%=item %>" /> </div>
            <% }) %>
        </div>
    </div>
</div>


JS

//msite 的轮播
var certifySwiper1 = new Swiper('#certify1 .swiper-container', {
    watchSlidesProgress: true,
    slidesPerView: 'auto',
    centeredSlides: false,
    loop: true,
    // autoplay: true,
    autoplay: {
        disableOnInteraction: false,
        delay:2000,
    },
    loopedSlides: 5,
    navigation: {
        nextEl: '.swiper-button-next',
        prevEl: '.swiper-button-prev',
    },
    pagination: {
        el: '.swiper-pagination',
        //clickable :true,
    },
    on: {
        progress: function (progress) {
            for (var i = 0; i < this.slides.length; i++) {
                var slide = this.slides.eq(i);
                var slideProgress = this.slides[i].progress;
 
                var modify = 1;
                if (Math.abs(slideProgress) > 1) {
                    modify = (Math.abs(slideProgress) - 1) * 0.1 + 1;
                }
 
                // var translate = slideProgress * modify * 114 + 'px';
                var translate = slideProgress * modify * 150 + 'px';
                var scale = 1 - Math.abs(slideProgress) / 7;
                var 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);
            }
 
        }
    }
 
})



本文标签: #幻灯
整理员:网络
免责声明:凡注明来源本网的所有作品,均为本网合法拥有版权或有权使用的作品,欢迎转载,注明出处。非本网作品均来自互联网,转载目的在于传递更多信息,并不代表本网赞同其观点和对其真实性负责。
生成海报
您可能在找更多

hammer.js的常规使用

    hammer.js是一个开源的库,他可以的实现在移端开发的大多数事件,如:点击、滑动、拖动、多点触控等事件。hammer.js不需要依赖任何其他的js框架,并且整个框架非常小Pan:拖动事件1、Pan:拖动事件!DOCTYPEhtmlhtmlh

网络转载 JavaScript教程2023-03-31

图片Slider 带左右按钮

    直接上整体

网络转载 HTML相关 12021-12-23

原生js实现移动端+pc端 轮播插件

    slide.js原生js写的轮播兼容 pc+移动端 插件,支持轮播速度,轮播内容,轮播间隔,手势灵敏度自定义,导航

网络转载 HTML相关2021-12-23

swiper点击切换,拖动切换后继续自动轮播

    用代码测试

小黑 JS相关2020-07-20

jQuery网站导航加轮播图

小黑 导航2020-07-12

下一篇
我来说两句
抢沙发