heightStyle: “fill” is not working for accordion in Jquery

允我心安 提交于 2019-12-05 12:36:19
Paul S.

I have been fighting the same problem as you. My site is using jQuery 1.9.1 and jQueryUI 1.10.2. All my efforts had been on the parent div, but nothing from the documentation or discussions had worked. Yesterday I discovered the SO topic jquery 1.9 accordion height issue in which Mottie suggests modifying the CSS for each accordion panel instead of the parent:

#accordion .ui-accordion-content {    
    max-height: 400px;
    overflow-y: auto;
}

In the limited testing I have done since yesterday, this has solved my problem of the accordion overflowing its container.

The apperance suggests that there is a float that hasn't been cleared, causing the wrapping container to appear as it does. Try adding a "clear" element after your accordions:

.clearer{
clear:both:
height:1px;
margin-bottom:-1px;
}

<div id="backlogEpic" class="ui-widget-content">
    <div id="backlogAccordion">  
    <--- accordian code---->   
    </div> 
    <div class='clearer'></div>
</div>

Try this. On create event:

  1. count the accordion header --> c
  2. calculate the content height : parent's height (#content) - (c * acordion height)
  3. set the content (.ui-accordion-content) outer height;

you should be aware about height vs innerheight vs outerheight of jquery

$( "#accordion" ).accordion({
    heightStyle: "fill",
    collapsible:true,
    active:false,
    animate:300,
    create: function( event, ui ) {
        var c=$(".ui-accordion-header").length;
        var h=$("#content").height() - (c* $(".ui-accordion-header").outerHeight(true));
        $(".ui-accordion-content").outerHeight(h);
    }
});
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!