Home  >  Article  >  Web Front-end  >  Example of the method of vertically centering long images on top and short images in vue

Example of the method of vertically centering long images on top and short images in vue

小云云
小云云Original
2018-01-09 13:35:082443browse

This article mainly introduces in detail the elastic layout of vue to realize the vertical centering of long images on the top, and the vertical centering of short images in vue. It has certain reference value. Interested friends can refer to it. I hope it can help everyone.

The approximate effect is as shown below, only the vertical direction is considered. Long pictures can be viewed through the scroll bar, short pictures have a centered effect, and the layout is reasonable

html code (within vue scope):


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

css code:


.box{
 height: 100%;//如高度等于网页高度
 overflow: auto;
 display: flex;
 flex-direction: column;
 justify-content: space-around;
}
.swiper-slide.long{
 justify-content: flex-start;
}

js code (within vue scope, using jquery):


methods: {
checkHeight:function (event) {
  var el=$(event.currentTarget);
  el.parent().removeClass(&#39;long&#39;);
  //this.CH 为网页高度
  if(el.height()>this.CH){
    el.parent().addClass(&#39;long&#39;);
  }

}

}

Related recommendations:

How to vertically center a div in css

css to achieve horizontal and vertical centering of elements

What are the two ways to set the horizontal and vertical centering of elements

The above is the detailed content of Example of the method of vertically centering long images on top and short images in vue. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn