美文网首页微信小程序开发
wx小程序-swiper显示上一张下一张压边且无缝轮播

wx小程序-swiper显示上一张下一张压边且无缝轮播

作者: 倩仔6 | 来源:发表于2020-01-14 14:03 被阅读0次

    特点1:扩展左右滑动两边各显示一半其它的item

    特点2:无缝轮播:在swiper中加circular属性即可

    效果:


    swiper1 siwper2

    index.wxml

    <!-- 轮播  next-margin="40rpx" previous-margin="40rpx" -->
      <swiper circular class="banner" next-margin="40rpx" previous-margin="40rpx" indicator-dots="true" autoplay="true" interval="3000" duration="1000">
          <swiper-item wx:for="{{banner}}" wx:key="id" class="back">
              <block wx:if="{{item.link>0}}" class="bannerimge">
                  <navigator url="/pages/goods/goods?id={{item.link}}">
                      <image style="margin:0px;border:0px;width:100%;height:100%" src="{{item.url}}" background-size="cover"></image>
                  </navigator>
              </block>
              <block wx:else class="bannerimge">
                  <image src="{{item.url}}" background-size="cover"></image>
              </block>
          </swiper-item>
      </swiper>
    


    <swiper circular class="banner" next-margin="40rpx" previous-margin="40rpx" indicator-dots="true" autoplay="true" interval="3000" duration="1000">
    <swiper-item wx:for="{{banner}}" wx:key="id" class="back">
    <block wx:if="{{item.link>0}}" class="bannerimge">
    <navigator url="/pages/goods/goods?id={{item.link}}">
    <image style="margin:0px;border:0px;width:100%;height:100%" src="{{item.url}}" background-size="cover"></image>
    </navigator>
    </block>
    <block wx:else class="bannerimge">
    <image src="{{item.url}}" background-size="cover"></image>
    </block>
    </swiper-item>
    </swiper>

    index.wxss

    .banner {
        width: 100%;
        height: 306rpx;
        background-color: #ffffff;
    }
    
    .banner .back {
        width: 670rpx;
        height: 306rpx;
        display: flex;
        justify-content: center;
        align-items: center;
    }
    
    .banner .back image {
        width: 670rpx;
        height: 306rpx;
        margin-left: 10rpx;
        margin-right: 10rpx;
    }
    

    .banner {
    width: 100%;
    height: 306rpx;
    background-color: #ffffff;
    }

    .banner .back {
    width: 670rpx;
    height: 306rpx;
    display: flex;
    justify-content: center;
    align-items: center;
    }

    .banner .back image {
    width: 670rpx;
    height: 306rpx;
    margin-left: 10rpx;
    margin-right: 10rpx;
    }

    另外补:banner json

    "banner":[
    {
    "id":1,
    "link":"",
    "url":"http://dev-ywzt-bucket.oss-cn-beijing.aliyuncs.com/item/2020-01-07/a46277ace4994ff4bfdaf19f5ddffc3b.jpg",
    },
    {
    "id":2,
    "link":"",
    "url":"http://dev-ywzt-bucket.oss-cn-beijing.aliyuncs.com/item/2020-01-07/5b436bf4687c4129b92cddfd2ab13f8e.jpg",
    },
    {
    "id":3,
    "link":"",
    "url":"http://dev-ywzt-bucket.oss-cn-beijing.aliyuncs.com/item/2020-01-07/330957b2ce914329a5bc3cbffb9ffcb2.jpg",
    
    }
    ],
    

    "banner":[
    {
    "id":1,
    "link":"",
    "url":"http://dev-ywzt-bucket.oss-cn-beijing.aliyuncs.com/item/2020-01-07/a46277ace4994ff4bfdaf19f5ddffc3b.jpg",
    },
    {
    "id":2,
    "link":"",
    "url":"http://dev-ywzt-bucket.oss-cn-beijing.aliyuncs.com/item/2020-01-07/5b436bf4687c4129b92cddfd2ab13f8e.jpg",
    },
    {
    "id":3,
    "link":"",
    "url":"http://dev-ywzt-bucket.oss-cn-beijing.aliyuncs.com/item/2020-01-07/330957b2ce914329a5bc3cbffb9ffcb2.jpg",

    }
    ],

    相关文章

      网友评论

        本文标题:wx小程序-swiper显示上一张下一张压边且无缝轮播

        本文链接:https://www.haomeiwen.com/subject/faxaactx.html