<div class="leftImg">
<el-carousel :initial-index="currentIndex" style="margin-top: 20px;" ref="carousel" :autoplay="false"
indicator-position="none">
<el-carousel-item v-for="(item, index) in images" :key="index">
<img :src="item">
</el-carousel-item>
</el-carousel>
<div class="thumbnails" ref="thumbnails">
<div class="thumbnails_con" v-for="(thumbnail, index) in images" :key="index"
@click="changeImage(index)">
<img :src="thumbnail" alt="" :class="{ active: activeThumb === index }">
</div>
</div>
</div>
//data
images: [
],
// 点击缩略图图
changeImage(index) {
this.activeThumb = index
this.$refs.carousel.setActiveItem(index)
this.onScroll()
},
onScroll() {
const container = this.$refs.thumbnails;
const thumbnailWidth = 100
const targetOffset = this.activeThumb * thumbnailWidth;
container.scrollLeft = targetOffset - (container.offsetWidth / 2) + (thumbnailWidth / 2);
}
//CSS
.thumbnails {
margin: 10px 0;
white-space: nowrap;
overflow-x: auto;
transition: scroll-left 0.5s ease;
&::-webkit-scrollbar {
display: none;
}
&_con {
display: inline-block;
margin-right: 10px;
transition: all .5s;
cursor: pointer;
img {
width: 105px;
height: 63px;
border: 4px solid #ccc;
border-radius: 5px;
}
&:last-child{
margin-right: 0;
}
}
.active {
border-color: rgb(102, 102, 102);
}
}
el-carousel 加缩略图联动走马灯
©著作权归作者所有,转载或内容合作请联系作者
- 文/潘晓璐 我一进店门,熙熙楼的掌柜王于贵愁眉苦脸地迎上来,“玉大人,你说我怎么就摊上这事。” “怎么了?”我有些...
- 文/花漫 我一把揭开白布。 她就那样静静地躺着,像睡着了一般。 火红的嫁衣衬着肌肤如雪。 梳的纹丝不乱的头发上,一...
- 文/苍兰香墨 我猛地睁开眼,长吁一口气:“原来是场噩梦啊……” “哼!你这毒妇竟也来了?” 一声冷哼从身侧响起,我...
推荐阅读更多精彩内容
- 一.在Vue项目中安装依赖 二.导入依赖在main.js项目入口文件导入全局样式 三.新建Carousel.vue...
- 问题:当Carousel数据通过接口获取时,自动切换效果就会无效,且首页展示的高度为默认的最小高度;只有手动切换一...
- 页面展示如图所示 以下是vue中的布局 以下是修改element ui指示器的样式1、修改指示器样式.el-car...