Keyboard shortcuts

Press ← or → to navigate between chapters

Press ? to show this help

Press Esc to hide this help

slider

滑动选择器。

属性类型默认值必填说明最低版本
minNumber0否最小值 
maxNumber100否最大值 
stepNumber1否步长,取值必须大于 0,并且可被(max - min)整除 
disabledBooleanfalse否是否禁用 
valueNumber0否当前取值 
colorColor#888888否步长文字颜色 
activeColorColor#00cac4否已选择的颜色 
backgroundColorColor#e9e9e9否背景条的颜色 
block-sizeNumber28否滑块的大小,取值范围为 12 - 28 
block-colorColor#ffffff否滑块的颜色 
show-valueBooleanfalse否是否显示当前 value 
bindchangeEventHandle否完成一次拖动后触发的事件,event.detail = {value} 
bindchangingEventHandle否拖动过程中触发的事件,event.detail = {value} 

示例代码:

<!--pages/component/pages/slider/slider.mcml-->
<view class="container">
  <view class="statement">滑动选择器。</view>
  <block mc:for="{{props}}">
    <view class="cssname">{{item.name}}</view>
    <view>
      <slider  style="color:red;"
      min="{{item.min || 0}}" 
      max="{{item.max || 100}}" 
      step="{{item.step || 1}}" 
      disabled="{{item.disabled || false}}" 
      show-value="{{item.showValue || false}}"
      value="{{item.value || 0}}"
      color="{{item.color ? item.color : ''}}"
      selected-color="{{item.selectedColor ? item.selectedColor : '' }}"
      activeColor="{{item.activeColor ? item.activeColor : '' }}"
      backgroundColor="{{item.backgroundColor ? item.backgroundColor : '' }}"
      block-size="{{item.blockSize || 28}}"
      block-color="{{item.blockColor || '#fff'}}"
      bindchange="bindchange"
      bindchanging="bindchanging" 
      ></slider>
    </view>
  </block>
  <view class="cssname">bindchange</view>
  <text space="nbsp" user-select="true" class="scrollDetail">{{bindchange}}</text>
  <view class="cssname">bindchanging</view>
  <text space="nbsp" user-select="true" class="scrollDetail">{{bindchanging}}</text>
</view>
// pages/component/pages/slider/slider.js
Page({
  data: {
    props:[
      { name: 'min:10 , max: 200', value:30, min: 10, max: 200, showValue: true},
      { name: 'min:-200 , max: 10', value:-30, min: -200, max: 10, showValue: true},
      { name: 'step: 20', step: 20},
      { name: 'disabled', disabled: true, value: 60 },
      { name: 'show-value', showValue: true },
      { name: 'color', color: 'red', showValue: true, value: 40 },
      { name: 'activeColor', activeColor: 'red', value: 20 },
      { name: 'backgroundColor', backgroundColor: 'blue', value: 30 },
      { name: 'block-size', blockSize: 12 },
      { name: 'block-color', blockColor: 'green' }
    ]
  },
  bindchanging: function(e){
    this.setData({
      bindchanging: JSON.stringify(e.detail, 2, null)
    })
  },
  bindchange: function (e) {
    this.setData({
      bindchange: JSON.stringify(e.detail, 2, null)
    })
  }
})