简体   繁体   English

Bootstrap 3折叠:获取折叠元素的非折叠高度

[英]Bootstrap 3 collapse: Get non-collapsed height of a collapsed element

I have some bootstrap panels where the panel-heading is used to collapse the panel-body . 我有一些引导面板,其中panel-heading用于折叠panel-body I'm wondering if it's possible to access the non-collapsed height of the panel-body when it is in the collapsed state? 我想知道当panel-body处于折叠状态时是否可以访问其非折叠高度?

You can check out this jsFiddle , where the panel body is already collapsed. 您可以检出此jsFiddle ,其中面板主体已折叠。 Clicking the panel header will expand the body. 单击面板标题将展开正文。 When the body is collapsed, how can I determine its height when it's not collapsed (without expanding it)? 当身体崩溃时,我如何确定它没有崩溃时的高度(不扩展)?

This question is specific to Bootstrap 3 so this answer is as well and may not be useful generally. 这个问题是Bootstrap 3特有的,因此该答案也不错,通常可能没有用。

In bootstrap 3, when an element is collapsed its height is explicitly set to 0px using element styling. 在引导程序3中,当元素折叠时,使用元素样式将其高度显式设置为0px You can disable this in-line element styling and access its height via: 您可以通过以下方式禁用此嵌入式元素样式并访问其高度:

$(element_selector)['height']('').height();

This will not show the element, because in addition to setting the height to 0px , when the element is collapsed its display property is set to none . 这将不会显示该元素,因为除了将height设置为0px ,当该元素折叠时,其display属性也将设置为none

You can have track of how many element are inside the panel and than from there you could calculate his height: 您可以跟踪面板中有多少个元素,然后从那里可以计算出他的高度:

$(document).ready(function(){
  var rowHeight = 50;
  var marginBottom = 50;
  var nrOfRows = 0;
  $('.my-table .row').each(function(){
     nrOfRows ++
  })
  var panelHeight = (rowHeight*nrOfRows)+prseInt(marginBottom)
})

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM