在有限空間內(nèi),循環(huán)播放同一類型的圖片、文字等內(nèi)容
1.如何使用?
結(jié)合使用el-carousel
和el-carousel-item
標(biāo)簽就得到了一個(gè)走馬燈?;脽羝膬?nèi)容是任意的,需要放在el-carousel-item
標(biāo)簽中。默認(rèn)情況下,在鼠標(biāo) hover 時(shí)底部的指示器時(shí)就會(huì)觸發(fā)切換。通過(guò)設(shè)置trigger
屬性為click
,可以達(dá)到點(diǎn)擊觸發(fā)的效果。
<template>
<div class="block">
<span class="demonstration">默認(rèn) Hover 指示器觸發(fā)</span>
<el-carousel height="150px">
<el-carousel-item v-for="item in 4" :key="item">
<h3 class="small">{{ item }}</h3>
</el-carousel-item>
</el-carousel>
</div>
<div class="block">
<span class="demonstration">Click 指示器觸發(fā)</span>
<el-carousel trigger="click" height="150px">
<el-carousel-item v-for="item in 4" :key="item">
<h3 class="small">{{ item }}</h3>
</el-carousel-item>
</el-carousel>
</div>
</template>
<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>
2.輪播指示器
可以將指示器的顯示位置設(shè)置在容器外部
//indicator-position屬性定義了指示器的位置。默認(rèn)情況下,
//它會(huì)顯示在走馬燈內(nèi)部,設(shè)置為outside則會(huì)顯示在外部;設(shè)置為none則不會(huì)顯示指示器。
<template>
<el-carousel indicator-position="outside">
<el-carousel-item v-for="item in 4" :key="item">
<h3>{{ item }}</h3>
</el-carousel-item>
</el-carousel>
</template>
<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>
3.輪播切換箭頭
可以設(shè)置切換箭頭的顯示時(shí)機(jī)
//arrow屬性定義了切換箭頭的顯示時(shí)機(jī)。默認(rèn)情況下,
//切換箭頭只有在鼠標(biāo) hover 到走馬燈上時(shí)才會(huì)顯示;
//若將arrow設(shè)置為always,則會(huì)一直顯示;設(shè)置為never,則會(huì)一直隱藏。
<template>
<el-carousel :interval="5000" arrow="always">
<el-carousel-item v-for="item in 4" :key="item">
<h3>{{ item }}</h3>
</el-carousel-item>
</el-carousel>
</template>
<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>
4.卡片化
當(dāng)頁(yè)面寬度方向空間空余,但高度方向空間匱乏時(shí),可使用卡片風(fēng)格
//將type屬性設(shè)置為card即可啟用卡片模式。從交互上來(lái)說(shuō),
//卡片模式和一般模式的最大區(qū)別在于,可以通過(guò)直接點(diǎn)擊兩側(cè)的幻燈片進(jìn)行切換。
<template>
<el-carousel :interval="4000" type="card" height="200px">
<el-carousel-item v-for="item in 6" :key="item">
<h3 class="medium">{{ item }}</h3>
</el-carousel-item>
</el-carousel>
</template>
<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>
5.方向
默認(rèn)情況下,direction
?為?horizontal
。通過(guò)設(shè)置?direction
?為?vertical
?來(lái)讓走馬燈在垂直方向上顯示。
<template>
<el-carousel height="200px" direction="vertical" :autoplay="false">
<el-carousel-item v-for="item in 3" :key="item">
<h3 class="medium">{{ item }}</h3>
</el-carousel-item>
</el-carousel>
</template>
關(guān)于走馬燈組件的 大致使用方式就是這些,深入淺出可以前往Carousel輪播組件
?文章來(lái)源地址http://www.zghlxwxcb.cn/news/detail-691471.html文章來(lái)源:http://www.zghlxwxcb.cn/news/detail-691471.html
?
到了這里,關(guān)于ElementUI淺嘗輒止14:Carousel 走馬燈的文章就介紹完了。如果您還想了解更多內(nèi)容,請(qǐng)?jiān)谟疑辖撬阉鱐OY模板網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關(guān)文章,希望大家以后多多支持TOY模板網(wǎng)!