本文实例为大家分享了微信小程序轮播图自定义光标位置的具体代码,供大家参考,具体内容如下
如图
轮播图的光标可以用定位来改变上下左右的位置
wxml:
<!--start banner -->
<swiper class='home-swiper' autoplay='true' bindchange='changDot' interval='4000'>
<!-- 设置自动播放,切换间隔时间-->
<swiper-item wx:for="{{slider}}" wx:for-index="index" wx:key="slider">
<image src='{{item.img}}'></image>
</swiper-item>
</swiper>
<!-- 轮播图光标 -->
<view class="dots">
<block wx:for="{{slider}}" wx:key="slider">
<view class="dot {{index == swiperCurrent?'actives':''}}"></view>
</block>
</view>
<!-- end banner -->
wxss:
.home-swiper {
width: 100%;
height: 350rpx;
position: relative;
}
.home-swiper image {
width: 100%;
height: 100%;
}
.dots {
display: flex;
flex-direction: row;
position: absolute;
top: 311rpx;
width: 100%;
height: 50rpx;
justify-content: center;
}
.dots .dot {
width: 20rpx;
height: 20rpx;
margin-left: 12rpx;
background: #fff;
border-radius: 20rpx;
opacity: 0.44;
}
.dots .actives {
background-color: #fff;
opacity: 1;
}
js:
Page({
data: {
swiperCurrent: 0,
slider :[
{'img':'/img/img/1.jpg'},
{ 'img': '/img/img/1.jpg' },
{ 'img': '/img/img/1.jpg' },
{ 'img': '/img/img/1.jpg' },
{ 'img': '/img/img/1.jpg' }
]
},
// 轮播图下标
changDot(e) {
this.setData({
swiperCurrent: e.detail.current
});
},
onLoad: function(options) {
},
onReady: function() {
},
onShow: function() {
},
onHide: function() {
},
onUnload: function() {
},
onPullDownRefresh: function() {
},
onReachBottom: function() {
},
onShareAppMessage: function() {
}
})
以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持编程网。