微信小顺序完成类3D轮播图

在写微信小顺序时,有写到完成3D轮播图的结果,能够直接运用微信小顺序中自带的组件swiper来完成

  • 结果图以下:

《微信小顺序完成类3D轮播图》

1.swiper的相干属性

  • indicator-dots 是不是显现小圆点,也能够本身从新设置小圆点
  • circular 是不是连接滑动,就是完成无穷转动
  • previous-margin 与上一张图片的间距
  • next-margin 与下一张图片的间距
  • autoplay 完成自动转动

这里重要利用了circular完成无穷转动,然后再加上前后间距,再设置图片的层级和透明度就能够完成了,将图片及容器的高度设置好就差不多能够完成了

  • wxml文件
<!--carousel/index.wxml-->
<swiper class="imageContainer" bindchange="handleChange" previous-margin="50rpx" next-margin="50rpx" circular autoplay>
  <block wx:for="{{3}}" wx:key="{{index}}">
    <swiper-item class="item">
      <image class="itemImg {{currentIndex == index ? 'active': ''}}" src="../../../image/3.jpg"></image>
    </swiper-item>
  </block>
</swiper>
  • wxss文件
/* carousel/index.wxss */
page{
  background: #f7f7f7f7;
}
.imageContainer{
  width: 100%;
  height: 500rpx;
  background: #000;
}
.item{
  height: 500rpx;
}
.itemImg{
  position: absolute;
  width: 100%;
  height: 380rpx;
  border-radius: 15rpx;
  z-index: 5;
  opacity: 0.7;
  top: 13%;
}
.active{
  opacity: 1;
  z-index: 10;
  height: 430rpx;
  top: 7%;
  transition:all .2s ease-in 0s;
}
  • JS文件
// carousel/index.js
Page({

  data: {
    currentIndex: 0
  },

  onLoad: function (options) {
  
  },
  /* 这里完成掌握中心凸显图片的款式 */
  handleChange: function(e) {
    this.setData({
      currentIndex: e.detail.current
    })
  },
})

正在努力进修中,若对你的进修有协助,留下你的印记呗(点个赞咯^_^)

    原文作者:ZJW0215
    原文地址: https://segmentfault.com/a/1190000016185906
    本文转自网络文章,转载此文章仅为分享知识,如有侵权,请联系博主进行删除。
点赞