微信小程序-实现旋转木马轮播功能

2019-11-16   阅读:2804   分类:后端    标签: 微信小程序

效果图:

GIF.gif

技术要点:

自动滚动+手动拖拽 (原生组件帮我们完成 Property:autoplay)

面板指示点 (原生组件帮我们完成 Property:indicator-dots)

左右可以露出非Active状态图的边缘(即Quiet状态, 后文class会以这两个名字定义) (原生组件帮我们完成 Property:previous-margin、next-margin)

图片滚动到中心位置放大,滚动出去缩小 (我们手写实现,利用技术点中提到的滚动回调+条件渲染。其中滚动回调用 Property:bindchange)

.wxml 代码:

<!-- 轮播 -->
<view class="lunbo">
<swiper class='swiperClass' autoplay interval="3000" indicator-color="#a39f99" indicator-active-color="#f49641" indicator-dots  duration="1000" previous-margin="30rpx" next-margin="30rpx" circular bindchange="bindchange" style='height: {{swiperHeight}}rpx'>
<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>
</swiper>
</view>
<!-- 轮播 -->

.js 代码:

Page({
data: {
statusBarHeight: app.globalData.statusBarHeight,
imgUrls: [
'/pages/asset/images/index_03.jpg',
'/pages/asset/images/index_03.jpg',
'/pages/asset/images/index_03.jpg',
'/pages/asset/images/index_03.jpg'
],
indicatorDots: false,
swiperIndex: 0, //这里不写第一次启动展示的时候会有问题 
swiperCurrent: 0,
interval: 3000,
},

.wxss代码:

.lunbo{ width: 100%; float: left; margin-top:27rpx;}
.swiperClass {
margin: 0;
}

.slide-image {
width: 100%; 
height: 100%;
border-radius: 10px;
position: relative;
}

image.active {
transform: none;
transition: all 0.2s ease-in 0s;
} 

image.quiet {
transform: scale(0.95333333);
transition: all 0.2s ease-in 0s;
}


【腾讯云】 爆款2核2G3M云服务器首年 61元,2核2G4M云服务器新老同享 99元/年,续费同价

‘简忆博客’微信公众号 扫码关注‘简忆博客’微信公众号,获取最新文章动态
转载:请说明文章出处“来源简忆博客”。http://www.tpxhm.com/adetail/256.html

×
觉得文章有用就打赏一下文章作者
微信扫一扫打赏 微信扫一扫打赏
支付宝扫一扫打赏 支付宝扫一扫打赏

文章评论(0)

登录
简忆博客壁纸一
简忆博客壁纸二
简忆博客壁纸三
简忆博客壁纸四
简忆博客壁纸五
简忆博客壁纸六
简忆博客壁纸七
简忆博客壁纸八
头像

简忆博客
勤于学习,乐于分享

置顶推荐

打赏本站

如果你觉得本站很棒,可以通过扫码支付打赏哦!
微信扫码:你说多少就多少~
微信扫码
支付宝扫码:你说多少就多少~
支付宝扫码
×