繁体   English   中英

图像缩放以适合Bootstrap网格

[英]Image zoom to fit Bootstrap Grid

我里面有一个引导网格和图像。 我的图像大小不一样,所以我看到了一个难看的网格。 我希望所有图像看起来都一样大小。 我希望它们被缩放并隐藏图像的替代部分。

我正在尝试使用此代码,但未成功:

<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 -->

我知道将样式放在此处并不干净,而只是用于测试。

我认为这就是您要寻找的。

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:

<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>

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

暂无
暂无

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

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