继续浏览精彩内容
慕课网APP
程序员的梦工厂
打开
继续
感谢您的支持,我会继续努力的
赞赏金额会直接到老师账户
将二维码发送给自己后长按识别
微信支付
支付宝支付

微信小程序实现类3D轮播图

慕神8447489
关注TA
已关注
手记 1134
粉丝 172
获赞 955


在写微信小程序时,有写到实现3D轮播图的效果,可以直接使用微信小程序中自带的组件swiper来实现

效果图如下:

webp

image.png

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.jsPage({  data: {    currentIndex: 0
  },  onLoad: function (options) {
  
  },  /* 这里实现控制中间凸显图片的样式 */
  handleChange: function(e) {    this.setData({      currentIndex: e.detail.current
    })
  },
})



作者:IT智云编程
链接:https://www.jianshu.com/p/dd1f3238e9dd


打开App,阅读手记
0人推荐
发表评论
随时随地看视频慕课网APP

热门评论

慕课网小程序首页的那个轮播写的真好

查看全部评论