slider

滑动选择器。

效果展示

示例代码

WXML

<view class="page">
<view class="page__hd">
<text class="page__title">slider</text>
<text class="page__desc">滑块</text>
</view>
<view class="page__bd">
<view class="section section_gap">
<text class="section__title">设置step</text>
<view class="body-view">
<slider value="60" bindchange="slider2change" bindchanging="bindchanging" step="5" show-value/>
</view>
</view>

<view class="section section_gap">
<text class="section__title">显示当前value</text>
<view class="body-view">
<slider value="50" bindchange="slider3change" show-value/>
</view>
</view>

<view class="section section_gap">
<text class="section__title">设置最小/最大值</text>
<view class="body-view">
<slider value="100" bindchange="slider4change" min="50" max="200" show-value/>
</view>
</view>

<view class="section section_gap">
<text class="section__title">disabled</text>
<view class="body-view">
<slider value="60" disabled />
</view>
</view>

<view class="section section_gap">
<text class="section__title">color</text>
<view class="body-view">
<slider value="60" bindchange="slider5change" background-color="#ff0023" active-color="#ffa500" show-value />
</view>
</view>

<view>res_changing----{{res_changing}}</view>
<view>res_change----{{res_change}}</view>


<view class="section section_gap">
<text class="section__title">滑块大小</text>
<view class="body-view">
<slider value="60" bindchange="slider6change" block-size="6" show-value />
</view>
<view class="body-view">
<slider value="60" bindchange="slider6change" block-size="12" show-value />
</view>
<view class="body-view">
<slider value="60" bindchange="slider6change" block-size="14" show-value />
</view>
<view class="body-view">
<slider value="60" bindchange="slider6change" block-size="28" show-value />
</view>
<view class="body-view">
<slider value="60" bindchange="slider6change" block-size="40" show-value />
</view>
</view>

<view class="section section_gap">
<text class="section__title">滑块颜色</text>
<view class="body-view">
<slider value="60" bindchange="slider7change" block-color="#000000" show-value />
</view>
<view class="body-view">
<slider value="60" bindchange="slider7change" block-color="#00ee00" show-value />
</view>
</view>

<view class="section section_gap">
<text class="section__title">show-value</text>
<view class="body-view">
<slider value="60" bindchange="slider7change" block-color="#000000" show-value="true" />
</view>
<view class="body-view">
<slider value="60" bindchange="slider7change" block-color="#00ee00" show-value="{{false}}" />
</view>
<view class="body-view">
<slider value="60" bindchange="slider7change" block-color="#00ee00" show-value="false" />
</view>
<view class="body-view">
<slider value="60" bindchange="slider7change" block-color="#00ee00" show-value />
</view>
</view>
</view>
</view>

JS

var pageData = {
bindchanging: function (e) {
console.log("bindchanging", e.detail.value);
this.setData({
res_changing: "bindchanging" + e.detail.value
})
},
data: {
res_changing: 'changing',
res_change: 'change',
}
}
for(var i = 1; i < 8; ++i) {
(function (index) {
pageData[`slider${index}change`] = function(e) {
console.log(`slider${index}发生change事件,携带值为`, e.detail.value);
this.setData({
res_change: `slider${index}发生change事件,携带值为` + e.detail.value
})
}
})(i);
}
Page(pageData)

API

属性 类型 默认值 必填 说明
min number 0 最小值
max number 100 最大值
step number 1 步长,取值必须大于 0,并且可被(max - min)整除
disabled boolean false 是否禁用
value number 0 当前取值
active-color color #1aad19 已选择的颜色
background-color color #e9e9e9 背景条的颜色
block-size number 28 滑块的大小,取值范围为 12 - 28
block-color color #ffffff 滑块的颜色
show-value boolean false 是否显示当前 value
bindchange eventhandle 完成一次拖动后触发的事件,event.detail = {value}
bindchanging eventhandle 拖动过程中触发的事件,event.detail = {value}

多平台支持

属性 平台支持
min 支付宝
max 支付宝
step 支付宝
disabled 支付宝
value 支付宝
active-color 支付宝
background-color 支付宝
block-size 支付宝
block-color 支付宝
show-value 支付宝
bindchange 支付宝
bindchanging 支付宝