小程序旋转木马 轮播图

前言

看下效果吧

 

分析

自动滚动+手动拖拽 (原生组件帮我们完成 Property:autoplay)
面板指示点 (原生组件帮我们完成 Property:indicator-dots)
左右可以露出非Active状态图的边缘(即Quiet状态, 后文class会以这两个名字定义) (原生组件帮我们完成 Property:previous-margin、next-margin)
图片滚动到中心位置放大,滚动出去缩小 (我们手写实现,利用技术点中提到的滚动回调+条件渲染。其中滚动回调用 Property:bindchange)
这样看下来就很清晰了,需要我们实现的只有一个动画放大缩小。再进一步

直接上代码吧,嘻嘻

wxml

//.wxml
 <swiper class='swiperClass' autoplay indicator-color="#a39f99" indicator-active-color="#f49641" indicator-dots  interval="2000" duration="1000" previous-margin="30px" next-margin="30px" circular bindchange="bindchange" style='height: {{swiperHeight}}px'>
 <block wx:for="{{imgUrls}}" wx:key="{{index}}">
 <swiper-item>
 <image src="{{item}}" class="slide-image {{swiperIndex == index ? 'active' : 'quiet'}}" mode='aspectFill'>
 </image>
 </swiper-item>
 </block>

 

wxss

//.wxss
.swiperClass {
  margin: 0;
  margin-top: 10px;
}
 
.slide-image {
  width: 100%; 
  height: 90%;
  border-radius: 10px;
  position: relative;
}
 
image.active {
  transform: none;
  transition: all 0.2s ease-in 0s;
} 
 
image.quiet {
  transform: scale(0.8333333);
  transition: all 0.2s ease-in 0s;
//.js
data: {
    imgUrls: [
'http://img17.3lian.com/201612/16/88dc7fcc74be4e24f1e0bacbd8bef48d.jpg',
      'http://f0.topitme.com/0/6a/6c/11800178627706c6a0o.jpg',
 'http://img17.3lian.com/d/file/201701/05/14d111f12c9fa2796c774ffef1bbfe14.jpg',
 ],
    swiperIndex: 0 ,//这里不写第一次启动展示的时候会有问题
    swiperHeight:300
 },
 
bindchange(e) {
 this.setData({
      swiperIndex: e.detail.current
 })

 

转载于:https://www.cnblogs.com/yf-html/p/9566220.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值