我有一个Bootstrap网格和里面的图像。我的图像大小不一样,所以我得到了一个难看的网格。 我希望所有图像看起来都相同。我希望它们被缩放并隐藏图像的覆盖部分。
我正在尝试使用此代码,但没有成功:
<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 -->
我知道把风格放在那里并不干净,只是为了测试。
答案 0 :(得分:1)
我认为这就是你要找的东西。
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>