2016-12-22 16:10:55 +08:00
|
|
|
<script>
|
|
|
|
export default {
|
|
|
|
mounted() {
|
|
|
|
this.$nextTick(() => {
|
|
|
|
const demos = document.querySelectorAll('.source');
|
|
|
|
demos[0].style.padding = '0';
|
|
|
|
demos[0].className += ' small';
|
|
|
|
demos[3].className += ' medium';
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
</script>
|
|
|
|
<style>
|
|
|
|
.demo-carousel .block {
|
|
|
|
padding: 30px;
|
|
|
|
text-align: center;
|
|
|
|
border-right: solid 1px #EFF2F6;
|
2017-09-29 15:37:50 +08:00
|
|
|
display: inline-block;
|
2016-12-22 16:10:55 +08:00
|
|
|
width: 50%;
|
|
|
|
box-sizing: border-box;
|
|
|
|
&:last-child {
|
|
|
|
border-right: none;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
.demo-carousel .demonstration {
|
|
|
|
display: block;
|
|
|
|
color: #8492a6;
|
|
|
|
font-size: 14px;
|
|
|
|
margin-bottom: 20px;
|
|
|
|
}
|
|
|
|
|
|
|
|
.demo-carousel .el-carousel__container {
|
|
|
|
text-align: center;
|
|
|
|
}
|
|
|
|
|
|
|
|
.demo-carousel .el-carousel__item {
|
|
|
|
h3 {
|
2016-12-27 13:47:37 +08:00
|
|
|
color: #fff;
|
2016-12-22 16:10:55 +08:00
|
|
|
font-size: 18px;
|
|
|
|
line-height: 300px;
|
|
|
|
margin: 0;
|
|
|
|
}
|
|
|
|
&:nth-child(2n) {
|
|
|
|
background-color: #99a9bf;
|
|
|
|
}
|
|
|
|
&:nth-child(2n+1) {
|
|
|
|
background-color: #d3dce6;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
.demo-carousel .small h3 {
|
|
|
|
font-size: 14px;
|
|
|
|
line-height: 150px;
|
|
|
|
}
|
|
|
|
|
|
|
|
.demo-carousel .medium h3 {
|
|
|
|
font-size: 14px;
|
|
|
|
line-height: 200px;
|
|
|
|
}
|
|
|
|
</style>
|
|
|
|
## Carousel 走马灯
|
|
|
|
|
|
|
|
在有限空间内,循环播放同一类型的图片、文字等内容
|
|
|
|
|
|
|
|
### 基础用法
|
|
|
|
|
|
|
|
适用广泛的基础用法
|
|
|
|
|
2016-12-23 11:57:17 +08:00
|
|
|
::: demo 结合使用`el-carousel`和`el-carousel-item`标签就得到了一个走马灯。幻灯片的内容是任意的,需要放在`el-carousel-item`标签中。默认情况下,在鼠标 hover 底部的指示器时就会触发切换。通过设置`trigger`属性为`click`,可以达到点击触发的效果。
|
2016-12-22 16:10:55 +08:00
|
|
|
```html
|
|
|
|
<template>
|
|
|
|
<div class="block">
|
2016-12-23 11:57:17 +08:00
|
|
|
<span class="demonstration">默认 Hover 指示器触发</span>
|
2016-12-22 16:10:55 +08:00
|
|
|
<el-carousel height="150px">
|
2017-04-28 14:03:42 +08:00
|
|
|
<el-carousel-item v-for="item in 4" :key="item">
|
2016-12-22 16:10:55 +08:00
|
|
|
<h3>{{ item }}</h3>
|
|
|
|
</el-carousel-item>
|
|
|
|
</el-carousel>
|
|
|
|
</div>
|
|
|
|
<div class="block">
|
2016-12-23 11:57:17 +08:00
|
|
|
<span class="demonstration">Click 指示器触发</span>
|
2016-12-22 16:10:55 +08:00
|
|
|
<el-carousel trigger="click" height="150px">
|
2017-04-28 14:03:42 +08:00
|
|
|
<el-carousel-item v-for="item in 4" :key="item">
|
2016-12-22 16:10:55 +08:00
|
|
|
<h3>{{ item }}</h3>
|
|
|
|
</el-carousel-item>
|
|
|
|
</el-carousel>
|
|
|
|
</div>
|
|
|
|
</template>
|
2016-12-22 17:41:49 +08:00
|
|
|
|
|
|
|
<style>
|
|
|
|
.el-carousel__item h3 {
|
|
|
|
color: #475669;
|
|
|
|
font-size: 14px;
|
|
|
|
opacity: 0.75;
|
|
|
|
line-height: 150px;
|
|
|
|
margin: 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
.el-carousel__item:nth-child(2n) {
|
|
|
|
background-color: #99a9bf;
|
|
|
|
}
|
|
|
|
|
|
|
|
.el-carousel__item:nth-child(2n+1) {
|
|
|
|
background-color: #d3dce6;
|
|
|
|
}
|
|
|
|
</style>
|
2016-12-22 16:10:55 +08:00
|
|
|
```
|
|
|
|
:::
|
|
|
|
|
2016-12-23 11:57:17 +08:00
|
|
|
### 指示器
|
2016-12-22 16:10:55 +08:00
|
|
|
|
2016-12-23 11:57:17 +08:00
|
|
|
可以将指示器的显示位置设置在容器外部
|
2016-12-22 16:10:55 +08:00
|
|
|
|
2016-12-23 16:19:39 +08:00
|
|
|
::: demo `indicator-position`属性定义了指示器的位置。默认情况下,它会显示在走马灯内部,设置为`outside`则会显示在外部;设置为`none`则不会显示指示器。
|
2016-12-22 16:10:55 +08:00
|
|
|
```html
|
|
|
|
<template>
|
2016-12-23 11:57:17 +08:00
|
|
|
<el-carousel indicator-position="outside">
|
2017-04-28 14:03:42 +08:00
|
|
|
<el-carousel-item v-for="item in 4" :key="item">
|
2016-12-22 16:10:55 +08:00
|
|
|
<h3>{{ item }}</h3>
|
|
|
|
</el-carousel-item>
|
|
|
|
</el-carousel>
|
|
|
|
</template>
|
2016-12-22 17:41:49 +08:00
|
|
|
|
|
|
|
<style>
|
|
|
|
.el-carousel__item h3 {
|
|
|
|
color: #475669;
|
|
|
|
font-size: 18px;
|
|
|
|
opacity: 0.75;
|
|
|
|
line-height: 300px;
|
|
|
|
margin: 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
.el-carousel__item:nth-child(2n) {
|
|
|
|
background-color: #99a9bf;
|
|
|
|
}
|
|
|
|
|
|
|
|
.el-carousel__item:nth-child(2n+1) {
|
|
|
|
background-color: #d3dce6;
|
|
|
|
}
|
|
|
|
</style>
|
2016-12-22 16:10:55 +08:00
|
|
|
```
|
|
|
|
:::
|
|
|
|
|
|
|
|
### 切换箭头
|
|
|
|
可以设置切换箭头的显示时机
|
|
|
|
|
2016-12-23 11:57:17 +08:00
|
|
|
::: demo `arrow`属性定义了切换箭头的显示时机。默认情况下,切换箭头只有在鼠标 hover 到走马灯上时才会显示;若将`arrow`设置为`always`,则会一直显示;设置为`never`,则会一直隐藏。
|
2016-12-22 16:10:55 +08:00
|
|
|
```html
|
|
|
|
<template>
|
2016-12-23 11:57:17 +08:00
|
|
|
<el-carousel :interval="5000" arrow="always">
|
2017-04-28 14:03:42 +08:00
|
|
|
<el-carousel-item v-for="item in 4" :key="item">
|
2016-12-22 16:10:55 +08:00
|
|
|
<h3>{{ item }}</h3>
|
|
|
|
</el-carousel-item>
|
|
|
|
</el-carousel>
|
|
|
|
</template>
|
2016-12-22 17:41:49 +08:00
|
|
|
|
|
|
|
<style>
|
|
|
|
.el-carousel__item h3 {
|
|
|
|
color: #475669;
|
|
|
|
font-size: 18px;
|
|
|
|
opacity: 0.75;
|
|
|
|
line-height: 300px;
|
|
|
|
margin: 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
.el-carousel__item:nth-child(2n) {
|
|
|
|
background-color: #99a9bf;
|
|
|
|
}
|
|
|
|
|
|
|
|
.el-carousel__item:nth-child(2n+1) {
|
|
|
|
background-color: #d3dce6;
|
|
|
|
}
|
|
|
|
</style>
|
2016-12-22 16:10:55 +08:00
|
|
|
```
|
|
|
|
:::
|
|
|
|
|
|
|
|
### 卡片化
|
|
|
|
当页面宽度方向空间空余,但高度方向空间匮乏时,可使用卡片风格
|
|
|
|
|
2016-12-23 16:19:39 +08:00
|
|
|
::: demo 将`type`属性设置为`card`即可启用卡片模式。从交互上来说,卡片模式和一般模式的最大区别在于,可以通过直接点击两侧的幻灯片进行切换。
|
2016-12-22 16:10:55 +08:00
|
|
|
```html
|
|
|
|
<template>
|
2016-12-23 16:19:39 +08:00
|
|
|
<el-carousel :interval="4000" type="card" height="200px">
|
2017-04-28 14:03:42 +08:00
|
|
|
<el-carousel-item v-for="item in 6" :key="item">
|
2016-12-22 16:10:55 +08:00
|
|
|
<h3>{{ item }}</h3>
|
|
|
|
</el-carousel-item>
|
|
|
|
</el-carousel>
|
|
|
|
</template>
|
2016-12-22 17:41:49 +08:00
|
|
|
|
|
|
|
<style>
|
|
|
|
.el-carousel__item h3 {
|
|
|
|
color: #475669;
|
|
|
|
font-size: 14px;
|
|
|
|
opacity: 0.75;
|
|
|
|
line-height: 200px;
|
|
|
|
margin: 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
.el-carousel__item:nth-child(2n) {
|
|
|
|
background-color: #99a9bf;
|
|
|
|
}
|
|
|
|
|
|
|
|
.el-carousel__item:nth-child(2n+1) {
|
|
|
|
background-color: #d3dce6;
|
|
|
|
}
|
|
|
|
</style>
|
2016-12-22 16:10:55 +08:00
|
|
|
```
|
|
|
|
:::
|
|
|
|
|
2016-12-23 16:19:39 +08:00
|
|
|
### Carousel Attributes
|
2016-12-22 16:10:55 +08:00
|
|
|
| 参数 | 说明 | 类型 | 可选值 | 默认值 |
|
|
|
|
|---------- |-------------- |---------- |-------------------------------- |-------- |
|
2017-04-06 18:43:43 +08:00
|
|
|
| height | 走马灯的高度 | string | — | — |
|
2016-12-22 16:10:55 +08:00
|
|
|
| initial-index | 初始状态激活的幻灯片的索引,从 0 开始 | number | — | 0 |
|
2016-12-23 11:57:17 +08:00
|
|
|
| trigger | 指示器的触发方式 | string | click | — |
|
2016-12-23 16:19:39 +08:00
|
|
|
| autoplay | 是否自动切换 | boolean | — | true |
|
2016-12-23 11:57:17 +08:00
|
|
|
| interval | 自动切换的时间间隔,单位为毫秒 | number | — | 3000 |
|
2016-12-23 16:19:39 +08:00
|
|
|
| indicator-position | 指示器的位置 | string | outside/none | — |
|
|
|
|
| arrow | 切换箭头的显示时机 | string | always/hover/never | hover |
|
|
|
|
| type | 走马灯的类型 | string | card | — |
|
2016-12-22 16:10:55 +08:00
|
|
|
|
2016-12-23 16:19:39 +08:00
|
|
|
### Carousel Events
|
2016-12-22 16:10:55 +08:00
|
|
|
| 事件名称 | 说明 | 回调参数 |
|
|
|
|
|---------|---------|---------|
|
2016-12-23 16:19:39 +08:00
|
|
|
| change | 幻灯片切换时触发 | 目前激活的幻灯片的索引,原幻灯片的索引 |
|
2016-12-22 16:10:55 +08:00
|
|
|
|
2016-12-23 16:19:39 +08:00
|
|
|
### Carousel Methods
|
2016-12-22 16:10:55 +08:00
|
|
|
| 方法名 | 说明 | 参数 |
|
2016-12-29 22:07:50 +08:00
|
|
|
|---------- |-------------- | -- |
|
2016-12-23 16:19:39 +08:00
|
|
|
| setActiveItem | 手动切换幻灯片 | 需要切换的幻灯片的索引,从 0 开始;或相应 `el-carousel-item` 的 `name` 属性值 |
|
|
|
|
| prev | 切换至上一张幻灯片 | — |
|
|
|
|
| next | 切换至下一张幻灯片 | — |
|
|
|
|
|
|
|
|
### Carousel-Item Attributes
|
|
|
|
| 参数 | 说明 | 类型 | 可选值 | 默认值 |
|
|
|
|
|---------- |-------------- |---------- |-------------------------------- |-------- |
|
|
|
|
| name | 幻灯片的名字,可用作 `setActiveItem` 的参数 | string | — | — |
|
2017-05-02 10:24:40 +08:00
|
|
|
| label | 该幻灯片所对应指示器的文本 | string | — | — |
|