Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
假设元素的高度设置为“自动”。尝试在 jQuery 中获取高度会返回计算出的高度。有没有办法获取实际的 CSS 值(自动)而不是像素高度?
$('#myDiv').height() // returns calculated height
见http://jsfiddle.net/7GrwJ/
可以检索原始 CSS 值,请参阅此小提琴的结果(在 Firefox 和 Chromium 中测试)
我使用这个答案来获取原始的 css 对象,并使用这个 gist来模拟一个只对 Webkit 原生可用的必需函数。
之后,访问该属性很容易:
css($('#myDiv')).height