[improvement] Swipe: add indicator color prop (#2110)

This commit is contained in:
neverland 2018-11-20 21:00:09 +08:00 committed by GitHub
parent bf9db97921
commit acac16f4c5
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 27 additions and 7 deletions

View File

@ -1,7 +1,10 @@
<template> <template>
<demo-section> <demo-section>
<demo-block :title="$t('basicUsage')"> <demo-block :title="$t('basicUsage')">
<van-swipe :autoplay="3000"> <van-swipe
:autoplay="3000"
indicator-color="white"
>
<van-swipe-item>1</van-swipe-item> <van-swipe-item>1</van-swipe-item>
<van-swipe-item>2</van-swipe-item> <van-swipe-item>2</van-swipe-item>
<van-swipe-item>3</van-swipe-item> <van-swipe-item>3</van-swipe-item>
@ -21,7 +24,10 @@
</demo-block> </demo-block>
<demo-block :title="$t('title3')"> <demo-block :title="$t('title3')">
<van-swipe @change="onChange"> <van-swipe
indicator-color="white"
@change="onChange"
>
<van-swipe-item>1</van-swipe-item> <van-swipe-item>1</van-swipe-item>
<van-swipe-item>2</van-swipe-item> <van-swipe-item>2</van-swipe-item>
<van-swipe-item>3</van-swipe-item> <van-swipe-item>3</van-swipe-item>
@ -33,6 +39,7 @@
<van-swipe <van-swipe
vertical vertical
:autoplay="3000" :autoplay="3000"
indicator-color="white"
class="demo-swipe--vertical" class="demo-swipe--vertical"
> >
<van-swipe-item>1</van-swipe-item> <van-swipe-item>1</van-swipe-item>
@ -47,6 +54,7 @@
:autoplay="3000" :autoplay="3000"
:width="300" :width="300"
:loop="false" :loop="false"
indicator-color="white"
> >
<van-swipe-item>1</van-swipe-item> <van-swipe-item>1</van-swipe-item>
<van-swipe-item>2</van-swipe-item> <van-swipe-item>2</van-swipe-item>

View File

@ -13,7 +13,7 @@ Vue.use(Swipe).use(SwipeItem);
Use `autoplay` prop to set autoplay interval Use `autoplay` prop to set autoplay interval
```html ```html
<van-swipe :autoplay="3000"> <van-swipe :autoplay="3000" indicator-color="white">
<van-swipe-item>1</van-swipe-item> <van-swipe-item>1</van-swipe-item>
<van-swipe-item>2</van-swipe-item> <van-swipe-item>2</van-swipe-item>
<van-swipe-item>3</van-swipe-item> <van-swipe-item>3</van-swipe-item>
@ -128,7 +128,8 @@ export default {
| loop | Whether to enable loop | `Boolean` | `true` | | loop | Whether to enable loop | `Boolean` | `true` |
| vertical | Vertical Scrolling | `Boolean` | `false` | | vertical | Vertical Scrolling | `Boolean` | `false` |
| touchable | Whether touchable | `Boolean` | `true` | | touchable | Whether touchable | `Boolean` | `true` |
| show-indicators | Whether to show indocators | `Boolean` | `true` | | show-indicators | Whether to show indicators | `Boolean` | `true` |
| indicator-color | Indicator color | `String` | `#1989fa` |
| initial-swipe | Index of initial swipe, start from 0 | `Number` | `0` | | initial-swipe | Index of initial swipe, start from 0 | `Number` | `0` |
| width | Set Swiper Item Width | `Number` | `0` | | width | Set Swiper Item Width | `Number` | `0` |
| height | Set Swiper Item Height | `Number` | `0` | | height | Set Swiper Item Height | `Number` | `0` |

View File

@ -30,17 +30,19 @@
} }
&__indicator { &__indicator {
opacity: .3;
border-radius: 100%; border-radius: 100%;
background-color: @gray-dark; background-color: @blue;
width: @swipe-indicator; width: @swipe-indicator;
height: @swipe-indicator; height: @swipe-indicator;
transition: opacity .2s;
&:not(:last-child) { &:not(:last-child) {
margin-right: @swipe-indicator; margin-right: @swipe-indicator;
} }
&--active { &--active {
background-color: @orange; opacity: 1;
} }
} }
} }

View File

@ -19,6 +19,7 @@
<i <i
v-for="index in count" v-for="index in count"
:class="b('indicator', { active: index - 1 === activeIndicator })" :class="b('indicator', { active: index - 1 === activeIndicator })"
:style="indicatorStyle"
/> />
</div> </div>
</slot> </slot>
@ -40,6 +41,7 @@ export default create({
height: Number, height: Number,
autoplay: Number, autoplay: Number,
vertical: Boolean, vertical: Boolean,
indicatorColor: String,
loop: { loop: {
type: Boolean, type: Boolean,
default: true default: true
@ -144,6 +146,12 @@ export default create({
transitionDuration: `${this.swiping ? 0 : this.duration}ms`, transitionDuration: `${this.swiping ? 0 : this.duration}ms`,
transform: `translate${this.vertical ? 'Y' : 'X'}(${this.offset}px)` transform: `translate${this.vertical ? 'Y' : 'X'}(${this.offset}px)`
}; };
},
indicatorStyle() {
return {
backgroundColor: this.indicatorColor
};
} }
}, },

View File

@ -13,7 +13,7 @@ Vue.use(Swipe).use(SwipeItem);
通过`autoplay`属性设置自动轮播间隔 通过`autoplay`属性设置自动轮播间隔
```html ```html
<van-swipe :autoplay="3000"> <van-swipe :autoplay="3000" indicator-color="white">
<van-swipe-item>1</van-swipe-item> <van-swipe-item>1</van-swipe-item>
<van-swipe-item>2</van-swipe-item> <van-swipe-item>2</van-swipe-item>
<van-swipe-item>3</van-swipe-item> <van-swipe-item>3</van-swipe-item>
@ -128,6 +128,7 @@ export default {
| initial-swipe | 初始位置索引值 | `Number` | `0` | - | | initial-swipe | 初始位置索引值 | `Number` | `0` | - |
| loop | 是否开启循环播放 | `Boolean` | `true` | - | | loop | 是否开启循环播放 | `Boolean` | `true` | - |
| show-indicators | 是否显示指示器 | `Boolean` | `true` | - | | show-indicators | 是否显示指示器 | `Boolean` | `true` | - |
| indicator-color | 指示器颜色 | `String` | `#1989fa` | 1.4.5 |
| vertical | 是否为纵向滚动 | `Boolean` | `false` | 1.1.1 | | vertical | 是否为纵向滚动 | `Boolean` | `false` | 1.1.1 |
| touchable | 是否可以通过手势滑动 | `Boolean` | `true` | 1.1.1 | | touchable | 是否可以通过手势滑动 | `Boolean` | `true` | 1.1.1 |
| width | 滑块宽度 | `Number` | `0` | 1.2.1 | | width | 滑块宽度 | `Number` | `0` | 1.2.1 |