当前位置:Gxlcms > JavaScript > vue实现长图垂直居上 vue实现短图垂直居中

vue实现长图垂直居上 vue实现短图垂直居中

时间:2021-07-01 10:21:17 帮助过:48人阅读

大致效果如下图,只考虑垂直方向。长图可以通过滚动条看,短图居中效果,布局合理

html代码(vue作用域内):

  1. <div class="box" v-for="item in previewImg">
  2. <img :src="item" alt="" @load="checkHeight($event)">
  3. </div>

css代码:

  1. .box{
  2. height: 100%;//如高度等于网页高度
  3. overflow: auto;
  4. display: flex;
  5. flex-direction: column;
  6. justify-content: space-around;
  7. }
  8. .swiper-slide.long{
  9. justify-content: flex-start;
  10. }

js代码(vue作用域内,使用jquery):

  1. methods: {
  2. checkHeight:function (event) {
  3. var el=$(event.currentTarget);
  4. el.parent().removeClass('long');
  5.   //this.CH 为网页高度
  6. if(el.height()>this.CH){
  7. el.parent().addClass('long');
  8. }
  9. }
  10. }

以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持脚本之家。

人气教程排行