检测图像的高度 [英] Detect The Height of an Image

查看:149
本文介绍了检测图像的高度的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的项目有几个图片(有不同的大小),并改善页面的布局我为这些图片设置这个CSS:

I have several images(that have different sizes) on my project and to improve the layout of the page I've set this CSS for those images:

#Banners {
    max-width: 250px;
    max-height: 350px;

    border: 1px solid #fff;
    box-shadow: 0 0 5px #888;
    -moz-box-shadow: 0 0 5px #888;
    -webkit-box-shadow: 0 0 5px#888;
}

.float {
    float: left;
}

但有些图片小于 350px 和它们所在的容器的 min-height 设置为 360px 我的页面上的空间。所以我想获得图像的实际 height (通过CSS代码后的 height )并设置容器 min-height 等于使用jQuery的图片 height 。如何通过CSS传递图像后获取 height

But some images are smaller than 350px and the container they are in has the min-height set to 360px, then it lefts a blank space on my page. So I want to get the actual height of the image(the height after passing the CSS code) and set the container min-height equal to the image height using jQuery. How to get the image height after being passed through the CSS?

推荐答案

下面的代码应该这样做,但我不知道为什么你需要设置min-height等于图像的高度。

The code below should do it, however I'm not sure why you need to set the min-height equal to the height of the image.

$(document).ready(function () {
    $("#Banners").css("min-height", $("#img_id").outerHeight());
});

这篇关于检测图像的高度的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆