沉浸式阅读
Beta
转载

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

     订阅 HTML教程     2022-01-19     网络    640    0    0    0    2022-01-19
学习要点:效果用代码测试

示例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="https://www.mbkfw.com/static/image/lazy.gif" class="lazy" original=""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="https://www.mbkfw.com/static/image/lazy.gif" class="lazy" original=""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);
            }
 
        }
    }
 
})



本文标题: swiper轮播(中间大两边小滚动有过渡效果)

本文链接: https://www.mbkfw.com/course/1007.html (转载时请注明来源链接)

本文说明: 有问题或投稿请发送至: 邮箱/kf@dtmuban.com    QQ/290948585

特别鸣谢: 如果您觉得本文对您有帮助,请给我们一个小小的赞,收藏本文更利于反复学习哦!

 
本文标签: #幻灯
destoon程序前端开发标签生成器

下班PC阅读不方便?

手机也可以随时学习开发

微信关注公众号“商企云服”
"模板开发网前端开发教学"
每日干货技术分享
 
0

圈友点评

文明上网理性发言,请遵守网络评论服务协议

小编推荐



色彩
×

《客户实名在线注册登记》售后一直都在!

关注

微信
关注

微信扫一扫
不同的环境体验

幸运大转盘,好礼等您拿

模板开发网公众号

模板开发网微信小程序

代授权

程序
授权

黑小二

联系
客服

很高兴为您服务
尊敬的用户,欢迎您咨询,我们为新用户准备了优惠好礼。咨询客服

联系客服:

在线QQ: 290948585

客服电话: 18605917465

E_mail邮箱: kf@dtmuban.com

微信公众号: 商企云服

微信小程序: 模板开发

QQ客服 微信客服DT授权代办 在线交谈 智能小云

工作时间:

周一至周五: 09:00 - 18:00

APP下载

安卓
APK

模板开发网安卓版APP

反馈

我要
反馈