如何获取“自动” DIV的高度 [英] How do I get the "auto" height of a DIV

查看:138
本文介绍了如何获取“自动” DIV的高度的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

所以当我在一个div上使用jquery设置一个固定高度,例如 $('div')。height(200); c> $('div')。height()总是200.即使该div的内容超过了这个高度(我使用 overflow:hidden



如何获得DIV的真实高度,如同它处于自动模式? class =h2_lin>解决方案

USE

  .scrollHeight()

来自Vega的回答


So when I set a fixed height on a div with jquery, like $('div').height(200);, the value of $('div').height() is always 200. Even if the content from that div exceeds that height (I use overflow:hidden).

How can I get that true height of the DIV as if it would be in "auto" mode ?

解决方案

USE

.scrollHeight()

element.scrollHeight

with jquery try this

 $(selector)[0].scrollHeight

DESCRIPTION

An element's scrollHeight is a measurement of the height of an element's content including content not visible on the screen due to overflow.

Example

DEMO from Vega's Answer

这篇关于如何获取“自动” DIV的高度的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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