mirror of
https://gitee.com/vant-contrib/vant-weapp.git
synced 2025-04-06 03:58:05 +08:00
[new feature] Slider: add active-color、inactive-color prop (#1150)
This commit is contained in:
parent
34a048e134
commit
4e6cb6d036
@ -2,7 +2,7 @@ import Page from '../../common/page';
|
|||||||
|
|
||||||
Page({
|
Page({
|
||||||
data: {
|
data: {
|
||||||
currentValue: 30
|
currentValue: 50
|
||||||
},
|
},
|
||||||
|
|
||||||
onChange(event) {
|
onChange(event) {
|
||||||
|
@ -29,20 +29,29 @@
|
|||||||
custom-class="slider"
|
custom-class="slider"
|
||||||
value="50"
|
value="50"
|
||||||
step="10"
|
step="10"
|
||||||
bar-height="4px"
|
|
||||||
bind:change="onChange"
|
bind:change="onChange"
|
||||||
/>
|
/>
|
||||||
</demo-block>
|
</demo-block>
|
||||||
|
|
||||||
|
<demo-block title="自定义样式">
|
||||||
|
<van-slider
|
||||||
|
value="50"
|
||||||
|
custom-class="slider"
|
||||||
|
bar-height="4px"
|
||||||
|
active-color="#f44"
|
||||||
|
/>
|
||||||
|
</demo-block>
|
||||||
|
|
||||||
<demo-block title="自定义按钮">
|
<demo-block title="自定义按钮">
|
||||||
<van-slider
|
<van-slider
|
||||||
value="{{ currentValue }}"
|
value="{{ currentValue }}"
|
||||||
custom-class="slider"
|
custom-class="slider"
|
||||||
use-button-slot
|
use-button-slot
|
||||||
|
active-color="#f44"
|
||||||
bind:drag="onDrag"
|
bind:drag="onDrag"
|
||||||
>
|
>
|
||||||
<view class="custom-button" slot="button">
|
<view class="custom-button" slot="button">
|
||||||
{{ currentValue }}/100
|
{{ currentValue }}
|
||||||
</view>
|
</view>
|
||||||
</van-slider>
|
</van-slider>
|
||||||
</demo-block>
|
</demo-block>
|
||||||
|
@ -3,10 +3,10 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
.custom-button {
|
.custom-button {
|
||||||
width: 44px;
|
width: 26px;
|
||||||
color: #fff;
|
color: #fff;
|
||||||
font-size: 10px;
|
font-size: 10px;
|
||||||
line-height: 20px;
|
line-height: 18px;
|
||||||
text-align: center;
|
text-align: center;
|
||||||
border-radius: 100px;
|
border-radius: 100px;
|
||||||
background-color: #f44;
|
background-color: #f44;
|
||||||
|
@ -39,7 +39,45 @@ Page({
|
|||||||
#### 指定步长
|
#### 指定步长
|
||||||
|
|
||||||
```html
|
```html
|
||||||
<van-slider value="50" step="10" bar-height="4px" />
|
<van-slider value="50" step="10" />
|
||||||
|
```
|
||||||
|
|
||||||
|
#### 自定义样式
|
||||||
|
|
||||||
|
```html
|
||||||
|
<van-slider
|
||||||
|
value="50"
|
||||||
|
bar-height="4px"
|
||||||
|
active-color="#f44"
|
||||||
|
/>
|
||||||
|
```
|
||||||
|
|
||||||
|
#### 自定义按钮
|
||||||
|
|
||||||
|
```html
|
||||||
|
<van-slider
|
||||||
|
value="{{ currentValue }}"
|
||||||
|
use-button-slot
|
||||||
|
bind:drag="onDrag"
|
||||||
|
>
|
||||||
|
<view class="custom-button" slot="button">
|
||||||
|
{{ currentValue }}/100
|
||||||
|
</view>
|
||||||
|
</van-slider>
|
||||||
|
```
|
||||||
|
|
||||||
|
```js
|
||||||
|
Page({
|
||||||
|
data: {
|
||||||
|
currentValue: 50
|
||||||
|
},
|
||||||
|
|
||||||
|
onDrag(event) {
|
||||||
|
this.setData({
|
||||||
|
currentValue: event.detail.value
|
||||||
|
});
|
||||||
|
}
|
||||||
|
});
|
||||||
```
|
```
|
||||||
|
|
||||||
#### 自定义按钮
|
#### 自定义按钮
|
||||||
@ -80,6 +118,8 @@ Page({
|
|||||||
| min | 最小值 | `Number` | `0` |
|
| min | 最小值 | `Number` | `0` |
|
||||||
| step | 步长 | `Number` | `1` |
|
| step | 步长 | `Number` | `1` |
|
||||||
| bar-height | 进度条高度 | `String` | `2px` |
|
| bar-height | 进度条高度 | `String` | `2px` |
|
||||||
|
| active-color | 进度条激活态颜色 | `String` | `#1989fa` |
|
||||||
|
| inactive-color | 进度条默认颜色 | `String` | `#e5e5e5` |
|
||||||
|
|
||||||
### Event
|
### Event
|
||||||
|
|
||||||
|
@ -7,6 +7,8 @@ VantComponent({
|
|||||||
props: {
|
props: {
|
||||||
disabled: Boolean,
|
disabled: Boolean,
|
||||||
useButtonSlot: Boolean,
|
useButtonSlot: Boolean,
|
||||||
|
activeColor: String,
|
||||||
|
inactiveColor: String,
|
||||||
max: {
|
max: {
|
||||||
type: Number,
|
type: Number,
|
||||||
value: 100
|
value: 100
|
||||||
@ -80,6 +82,7 @@ VantComponent({
|
|||||||
});
|
});
|
||||||
|
|
||||||
this.$emit('drag', { value });
|
this.$emit('drag', { value });
|
||||||
|
|
||||||
if (end) {
|
if (end) {
|
||||||
this.$emit('change', value);
|
this.$emit('change', value);
|
||||||
}
|
}
|
||||||
|
@ -1,8 +1,12 @@
|
|||||||
<view
|
<view
|
||||||
class="custom-class van-slider {{ disabled ? 'van-slider--disabled' : '' }}"
|
class="custom-class van-slider {{ disabled ? 'van-slider--disabled' : '' }}"
|
||||||
|
style="{{ inactiveColor ? 'background:' + inactiveColor : '' }}"
|
||||||
bind:tap="onClick"
|
bind:tap="onClick"
|
||||||
>
|
>
|
||||||
<view class="van-slider__bar" style="{{ barStyle }}">
|
<view
|
||||||
|
class="van-slider__bar"
|
||||||
|
style="{{ barStyle }}; {{ activeColor ? 'background:' + activeColor : '' }}"
|
||||||
|
>
|
||||||
<view
|
<view
|
||||||
class="van-slider__button-wrapper"
|
class="van-slider__button-wrapper"
|
||||||
bind:touchstart="onTouchStart"
|
bind:touchstart="onTouchStart"
|
||||||
|
Loading…
x
Reference in New Issue
Block a user