vue实现长图垂直居上vue实现短图垂直居中⼤致效果如下图,只考虑垂直⽅向。长图可以通过滚动条看,短图居中效果,布局合理
html代码(vue作⽤域内):
<div class="box" v-for="item in previewImg">
<img :src="item" alt="" @load="checkHeight($event)">
</div>
css代码:
.box{
height: 100%;//如⾼度等于⽹页⾼度
overflow: auto;
display: flex;
flex-direction: column;
justify-content: space-around;
}
.swiper-slide.long{
justify-content: flex-start;
}
js代码(vue作⽤域内,使⽤jquery):
methods: {
checkHeight:function (event) {
css实现垂直水平居中var el=$(event.currentTarget);
el.parent().removeClass('long');
  //this.CH 为⽹页⾼度
if(el.height()>this.CH){
el.parent().addClass('long');
}
}
}
以上就是本⽂的全部内容,希望对⼤家的学习有所帮助,也希望⼤家多多⽀持。