微信小程序——【一】视图容器(view,scroll-view,swiper)之swiper组件(滑块视图容器)

本文深入讲解了Swiper组件的使用方法,包括其属性配置如indicator-dots、autoplay、interval和duration,以及如何通过JS动态调整这些属性。同时,提供了完整的WXML和JS代码示例,帮助读者快速上手。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

swiper

滑块视图容器。其中只可放置< swiper-item >组件,否则会导致未定义的行为。

属性类型默认值说明
indicator-dotsbooleanfalse是否显示面板指示点
autoplaybooleanfalse是否自动切换
indicator-dotsbooleanfalse是否显示面板指示点
intervalnumber5000自动切换时间间隔
durationnumber500滑动动画时长

swiper.wxml文件

<view class="container">
  <swiper indicator-dots="{{indicatorDots}}" autoplay="{{autoplay}}" interval="{{interval}}" duration="{{duration}}">
    <block wx:for="{{imgUrls}}">
      <swiper-item>
        <image src="{{item}}" class="{{slide-image}}"/>
      </swiper-item>
    </block>
  </swiper>

  <view>
    <button type="primary" bindtap="changeIndicatorDots">indicator-dots</button>
    <button type="primary" bindtap="changeAutoplay">autoplay</button>
  </view>

  <view>
    <slider bindchange="intervalChange" show-value min="500" max="2000"/>interval
    <slider bindchange="durationChange" show-value min="1000" max="10000"/>duration
  </view>

</view>

swiper.js文件

Page({

  /**
   * 页面的初始数据
   */
  data: {
    imgurls:[
      'https://images.unsplash.com/photo-1551334787-21e6bd3ab135?w=640',
      'https://images.unsplash.com/photo-1551214012-84f95e060dee?w=640',
      'https://images.unsplash.com/photo-1551446591-142875a901a1?w=640'
    ],
    indicatorDots:false,
    autoplay:false,
    interval:5000,
    duration:1000
  },
  changeIndicatorDots:function(e){
    this.setData({
      indicatorDots: !this.data.indicatorDots
    })
  },
  changeAutoplay:function(e){ 
    this.setData({
      autoplay:!this.data.autoplay
    })
  },
  intervalChange:function(e){
    this.setData({
      interval: e.detail.value
    })
  },
  durationChange:function(e){
    this.setData({
      duration: e.detail.value
    })
  }
})

效果图
在这里插入图片描述

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值