简体   繁体   English

图像缩放以适合Bootstrap网格

[英]Image zoom to fit Bootstrap Grid

I have a Bootstrap Grid and images inside. 我里面有一个引导网格和图像。 My images aren't the same size, so I get an ugly grid. 我的图像大小不一样,所以我看到了一个难看的网格。 I want all the images to look the same size. 我希望所有图像看起来都一样大小。 I want them to be zoomed and to hide the override part of the image. 我希望它们被缩放并隐藏图像的替代部分。

I'm trying with this code, but no success: 我正在尝试使用此代码,但未成功:

<div class='col-xs-6 col-sm-6 col-md-3 col-lg-2'>
    <a class="thumbnail fancybox" rel="ligthbox" href="url">
        <img class="img-responsive" style='-ms-object-fit: cover; -moz-object-fit: cover; -o-object-fit: cover; -webkit-object-fit: cover;  object-fit: cover;  overflow: hidden; -ms-transition: 1s all; -moz-transition: 1s all; -o-transition: 1s all; -webkit-transition: 1s all; transition: 1s all;' alt=""  src="url">
    </a>
</div> <!-- col-6 / end -->

I know its not clean to put the style right there, but just for tests. 我知道将样式放在此处并不干净,而只是用于测试。

I think this is what you're looking for. 我认为这就是您要寻找的。

JS: JS:

function squareThumbs() {
  var thumbs = document.getElementsByTagName("img");

  for (i = 0; i < thumbs.length; i++) {
    if (thumbs[i].parentNode.className.indexOf("thumbnail") != -1){
      thumbs[i].style.height = thumbs[i].clientWidth + "px";
      console.log(thumbs[i].clientWidth);
      console.log(thumbs[i].clientHeight);
    }
    console.log(thumbs[i].parentNode.className);
  }
}
squareThumbs();
window.onresize = squareThumbs;

HTML: HTML:

<div class="col-xs-6 col-sm-6 col-md-3 col-lg-2">
  <a class="thumbnail fancybox" rel="ligthbox" href="#" style="overflow:hidden;">
      <img src="http://placehold.it/100x125" class="img-responsive" style="width:100%;-ms-object-fit: cover; -moz-object-fit: cover; -o-object-fit: cover; -webkit-object-fit: cover;  object-fit: cover;  overflow: hidden; -ms-transition: 1s all; -moz-transition: 1s all; -o-transition: 1s all; -webkit-transition: 1s all; transition: 1s all;" alt="">
    </a>
</div>

Live Demo: http://www.bootply.com/bg1A4I9IJ0 现场演示: http//www.bootply.com/bg1A4I9IJ0

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM