原生小程序开发组件|视图容器组件汇总(二)

swiper

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

属性说明

属性类型默认值必填说明
indicator-dotsbooleanfalse是否显示面板指示点
indicator-colorcolor#666666指示点颜色
indicator-active-colorcolor#333333当前选中的指示点颜色
autoplaybooleanfalse是否自动切换
currentnumber0当前所在滑块的 index
intervalnumber5000自动切换时间间隔,单位 ms
durationnumber500滑动动画时长,单位 ms
circularbooleanfalse是否采用衔接滑动
verticalbooleanfalse滑动方向是否为纵向
bind:changeeventhandlecurrent 改变时会触发 change 事件,event.detail = {current, source}
bind:animationfinisheventhandle动画结束时会触发 animationfinish 事件,event.detail 同上

change 事件 source 返回值

change 事件的 source 字段,表示导致变更的原因,可能值如下:

说明
autoplay自动播放导致 swiper 变化
touch用户划动引起 swiper 变化
空字符串其它原因

示例代码

TYML
<view class="container">
  <view class="page-body">
    <view class="page-section page-section-spacing swiper">
      <swiper
        indicator-dots="{{indicatorDots}}"
        autoplay="{{autoplay}}"
        circular="{{circular}}"
        vertical="{{vertical}}"
        interval="{{interval}}"
        duration="{{duration}}"
        >
        <block ty:for="{{background}}" ty:key="*this">
          <swiper-item>
            <view class="swiper-item {{item}}"></view>
          </swiper-item>
        </block>
      </swiper>
    </view>
    <view class="page-section" style="margin-top: 40rpx;margin-bottom: 0;">
      <view class="tyui-cells tyui-cells_after-title">
        <view class="page-cell tyui-cell_switch">
          <view class="tyui-cell__bd">指示点</view>
          <view class="tyui-cell__ft">
            <switch checked="{{indicatorDots}}" bind:change="changeProperty" data-property-name="indicatorDots" />
          </view>
        </view>
        <view class="page-cell tyui-cell_switch">
          <view class="tyui-cell__bd">自动播放</view>
          <view class="tyui-cell__ft">
            <switch checked="{{autoplay}}" bind:change="changeProperty" data-property-name="autoplay" />
          </view>
        </view>
        <view class="page-cell tyui-cell_switch">
          <view class="tyui-cell__bd">衔接滑动</view>
          <view class="tyui-cell__ft">
            <switch checked="{{circular}}" bind:change="changeProperty" data-property-name="circular" />
          </view>
        </view>
        <view class="page-cell tyui-cell_switch">
          <view class="tyui-cell__bd">竖向</view>
          <view class="tyui-cell__ft">
            <switch checked="{{vertical}}" bind:change="changeProperty" data-property-name="vertical" />
          </view>
        </view>
      </view>
    </view>
 
    <view class="page-section page-section-spacing">
      <view class="page-section-title">
        <text>幻灯片切换时长(ms)</text>
        <text class="info">{{duration}}</text>
      </view>
      <slider value="{{duration}}" min="{{500}}" max="{{2000}}" bind:change="changeProperty" data-property-name="duration" />
      <view class="page-section-title">
        <text>自动播放间隔时长(ms)</text>
        <text class="info">{{interval}}</text>
      </view>
      <slider value="{{interval}}" min="{{2000}}" max="{{10000}}" bind:change="changeProperty" data-property-name="interval" />
    </view>
  </view>
</view>

👉 立即免费领取开发资源,体验涂鸦 MiniApp 小程序开发。    

JS
Page({
  data: {
    background: ['demo-text-1', 'demo-text-2', 'demo-text-3'],
    indicatorDots: true,
    vertical: false,
    autoplay: false,
    circular: true,
    interval: 2000,
    duration: 500,
    previousMargin: 0,
    nextMargin: 0,
  },
  change: function (e) {},
  changeProperty: function (e) {
    var propertyName = e.currentTarget.dataset.propertyName;
    var newData = {};
    newData[propertyName] = e.detail.value;
    this.setData(newData);
  },
  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,
    });
  },
});

 

swiper-item

滑块视图容器子项,仅可放置在 swiper 组件中,宽高自动设置为 100%。

👉 立即免费领取开发资源,体验涂鸦 MiniApp 小程序开发。     

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

打赏作者

IoT砖家涂拉拉

你的鼓励将是我创作的最大动力

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

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

打赏作者

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

抵扣说明:

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

余额充值