小程序的swiper组件实现轮播图-自定义轮播小圆点

 swiper组件

属性类型默认值必填说明最低版本
indicator-dotsbooleanfalse是否显示面板指示点1.0.0
indicator-colorcolorrgba(0, 0, 0, .3)指示点颜色1.1.0
indicator-active-colorcolor#000000当前选中的指示点颜色1.1.0
autoplaybooleanfalse是否自动切换1.0.0
currentnumber0当前所在滑块的 index1.0.0
intervalnumber5000自动切换时间间隔1.0.0
durationnumber500滑动动画时长1.0.0
circularbooleanfalse是否采用衔接滑动1.0.0
verticalbooleanfalse滑动方向是否为纵向1.0.0
previous-marginstring"0px"前边距,可用于露出前一项的一小部分,接受 px 和 rpx 值1.9.0
next-marginstring"0px"后边距,可用于露出后一项的一小部分,接受 px 和 rpx 值1.9.0
display-multiple-itemsnumber1同时显示的滑块数量1.9.0
skip-hidden-item-layoutbooleanfalse是否跳过未显示的滑块布局,设为 true 可优化复杂情况下的滑动性能,但会丢失隐藏状态滑块的布局信息1.9.0
easing-functionstring"default"指定 swiper 切换缓动动画类型2.6.5
bindchangeeventhandle current 改变时会触发 change 事件,event.detail = {current, source}1.0.0
bindtransitioneventhandle swiper-item 的位置发生改变时会触发 transition 事件,event.detail = {dx: dx, dy: dy}2.4.3
bindanimationfinisheventhandle 动画结束时会触发 animationfinish 事件,event.detail 同上1.9.0

swiper-item组件

仅可放置在swiper组件中,宽高自动设置为100%。

属性类型默认值必填说明最低版本
item-idstring 该 swiper-item 的标识符1.9.0

轮播图示例

 注意:
    轮播图中的image 中src属性
        填写图片地址时,如果直接src="/static/img/01.jpg"
        在模拟器上可以看到图片,但是真机调试就看不到图片了
    解决方法:
        在data中定义一个数组,存放图片的src地址
        data:{
            imgs:['/static/img/banners/1.jpg',....]
        }

        直接使用wx:for遍历
            <image src="{{item}}"

        这样既可以解决真机调试不显示图片的bug

wxml
<!-- swiper轮播
        宽度 100%
        高度设置为 150px
      swiper-item 子元素 不需要添加或修改他的默认样式
        宽高默认100% 根据父级自动改变
        image:默认宽高不是图片真实大小
  indicator-dots 是否显示圆点
  indicator-color 圆点颜色
  inidicator-active-color 当前颜色
  atuoplay 自动切换
  interval 切换时间间隔
  circular 是否衔接
  vertical 是否纵向滚动
-->
<swiper class="swiperfocus" indicator-dots="{{ showDots }}" indicator-color="rgba(255,0,0,.5)" indicator-active-color="#00f" autoplay interval="4000" circular vertical>
	<swiper-item wx:for="{{imgs}}" wx:key="index">
		<image src="{{item}}"></image>
	</swiper-item>
</swiper>
<view>-------------------模拟改变指示点样式--------------</view>
<view class="wrap">
	<swiper class="swiperfocus" autoplay circular current="{{current}}" bindchange="swiperCurrentchang">
		<swiper-item wx:for="{{imgs}}" wx:key="index">
			<image src="{{item}}"></image>
		</swiper-item>
	</swiper>
	<view class="dots">
		<text class="{{ index == current ? 'dotsactive' : '' }}"  wx:for="{{imgs}}" wx:key="index"></text>
	</view>
</view>
js
App({
  data: {
    showDots:true,
    imgs:['/static/img/banners/1.jpg','/static/img/banners/3.jpg','/static/img/banners/3.jpg'],
    current:0,
  },
  // 获取current
  swiperCurrentchang(e){
    // console.log(e,'获取current')
    let {current} = e.detail
    this.setData({
      current
    })
  }
})
/* pages/02swiper/02swiper.wxss */
.swiperfocus{
  height: 297rpx;
}

.swiperfocus image{
  /* width: 750rpx; */
  width: 100%;
  height: 100%;
}
.wrap{
  position: relative;
}
.wrap .swiperfocus{
  height: 297rpx;
}
.wrap .swiperfocus image{
  width: 100%;
  height: 100%;
}
.wrap .dots{
  position: absolute;
  bottom: 8rpx;
  left: 0;
  width: 100%;
  text-align: center;
}
.wrap .dots text{
  display: inline-block;
  width: 40rpx;
  height: 20rpx;
  background-color: blueviolet;
  margin: 0 12rpx;
  border-radius: 10rpx;
}
.wrap .dots .dotsactive{
  background-color: #fff;
}

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

JackieDYH

谢谢您嘞!我会继续加油地

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值