jquery手风琴获得高度值

时间:2015-06-04 23:55:41

标签: jquery height jquery-ui-accordion

我想在活动时获得各个面板的高度值。我知道我可以使用$(document).height()$(window).height(),但我想要活动面板的实际高度值。这可能吗?

<ul id="allTabs">                           
  <li><a id="tab-1" href="#buildTab" onclick='windowResize("mainAccordion");' >Build</a></li>
  <li><a id="tab-5" href="#setupTab" onclick='windowResize("setupAccordion");'>Setup</a></li>
</ul>

function windowResize(what){
  var setupActive=$('#mainSetupAccordion').accordion('option', 'active').toString();
  var mainActive=$('#accordion').accordion('option', 'active').toString();

  if (what=='setupAccordion'){
    var windowHeight=$('#mainSetupAccordion').outerHeight(true);
    var buttons=0;
  };

  if (what=='mainAccordion'){var windowHeight=$('#accordion').outerHeight(true); var buttons=25};
  if (setupActive=='false' && what=='setupAccordion'){windowHeight=104};
  if (mainActive=='false' && what=='mainAccordion'){windowHeight=79};      

  var window_size=windowHeight+87+buttons;

  $('#tab_sizes').val(window_size);
  window.location='skp:resizeWindow';
};    

基本上我试图让窗口随手风琴一起动态调整大小,如果我留在标签内,它会起作用。如果我切换标签,我得到的结果是0而不是手风琴面板值。

2 个答案:

答案 0 :(得分:1)

你可以使用

$('#activePanel').outerHeight(true);

如果你有多个手风琴给出所有相同的类并使用.each();

$('.Panels').each(function(){
     var actualHeight = $(this).outerHeight(true);
     console.log(actualHeight );
});

答案 1 :(得分:0)

我找到了一种方法来完成这项工作,修改了功能......它可能并不漂亮,但它确实有效。

function windowResize(what){
  var setupActive=$('#mainSetupAccordion').accordion('option', 'active').toString();
  var mainActive=$('#accordion').accordion('option', 'active').toString();

  if (what=='setupAccordion'){
    var windowHeight=$('#mainSetupAccordion').outerHeight(true);
    var buttons=0;
    if (setupActive=='false' && what=='setupAccordion'){windowHeight=104};
    if (windowHeight!=0) {
        setupAccordionPanel=[]
        setupAccordionPanel.push(windowHeight)
    }else{
        windowHeight=setupAccordionPanel[0]
    }
  };

  if (what=='mainAccordion'){
    var windowHeight=$('#accordion').outerHeight(true);
    var buttons=25
    if (mainActive=='false' && what=='mainAccordion'){windowHeight=79};      
    if (windowHeight!=0) {
        mainAccordionPanel=[]
        mainAccordionPanel.push(windowHeight)
    }else{
        windowHeight=mainAccordionPanel[0]
    }
  };

  var window_size=windowHeight+87+buttons;
  $('#tab_sizes').val(window_size);
  window.location='skp:resizeWindow';
};