【发布时间】:2014-11-07 06:38:32
【问题描述】:
从 Jquery 1.8 开始,在获取元素的 height() 时进行了更改。我有一个 CSS div 高度设置为自动,其中的图像通过使用 % 和 auto 来指示 div 的高度和宽度),当窗口加载时,我使用 Jquery 来获取元素的高度并在它旁边制作另一个 div相同的高度。在研究了这个之后,我注意到它在 CSS 设置图像设置的新高度之前返回高度。 1.7 允许这样做,但 1.8 及更高版本不允许。有解决办法吗。 这是css
#element1{ width:80%; height:auto;}
#element1 img{width:100%; height:auto};//this allows the image to resize with the page responsively.
jQuery...
$(window).ready(
function(){
var x = $("#element").height();
alert(x); // this would return what the height was dynamically set as by the css in 1.7, but 1.8 returns a small number that i am pretty certain is just the padding added to 0px
});
希望这是有道理的,并且有人可以解决。 谢谢
【问题讨论】:
-
如果你设置一个小提琴我可以帮助你更多,但试试
.outerHeight()? -
.outerHeight()是个好建议;这包括高度 + 边框 + 边距 + 填充
标签: javascript jquery html css height