elementUi 轮播图(Carousel 走马灯)的实现
程序员文章站
2022-01-15 11:59:34
...
elementUi官方自带轮播图
官网链接:http://element-cn.eleme.io/#/zh-CN/component/carousel
<template>
<div class="block">
<span class="demonstration">默认 Hover 指示器触发</span>
<el-carousel height="150px">
<el-carousel-item v-for="item in 4" :key="item">
<h3>{{ item }}</h3>
</el-carousel-item>
</el-carousel>
</div>
<div class="block">
<span class="demonstration">Click 指示器触发</span>
<el-carousel trigger="click" height="150px">
<el-carousel-item v-for="item in 4" :key="item">
<h3>{{ 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>
结合使用el-carousel
和el-carousel-item
标签就得到了一个走马灯。幻灯片的内容是任意的,需要放在el-carousel-item
标签中。默认情况下,在鼠标 hover 底部的指示器时就会触发切换。通过设置trigger
属性为click
,可以达到点击触发的效果。