转载请注明:【ElementUI】走马灯 el-carousel_joanmelon的博客-CSDN博客
carousel 的高度随着图片大小而更改
@load="imgLoad"
第一次加载页面跟踪图片高度
<el-carousel :height="imgHeight">
<el-carousel-item v-for="item in imgList" :key="item">
<img ref="imgHeight" :src="item.src" @load="imgLoad">
</el-carousel-item>
</el-carousel>
data: {
imgHeight: '',
},
mounted() {
this.imgLoad()
window.onresize = () => {
this.imgLoad()
}
},
methods:{
imgLoad(){
this.$nextTick(()=>{
this.imgHeight = this.$refs.imgHeight['0'].height +'px'
})
}
}
destroyed() {
window.onresize = null;
}
修改指示器样式
UI设计师经常会修改轮播图的指示器,并不会按照文档的样式来,今天遇到的就是常用的样式。
走马灯默认样式:
我们期望的样式:
设置样式的时候,一定要添加scoped
<style lang="less" scoped>
/deep/.el-carousel__indicators--horizontal {
position: absolute;
left: auto;
right: 10px;
bottom: 10px;
text-align: right;
.el-carousel__indicator--horizontal button {
width: 8px;
height: 8px;
background: #ffffff;
border-radius: 50%;
opacity: 0.5;
}
.el-carousel__indicator--horizontal.is-active button {
width: 24px;
height: 8px;
background: #ffffff;
opacity: 0.5;
border-radius: 10px;
}
}
</style>