JQUERY UI Accordion 在窗口调整大小时调整大小?

发布于 2024-08-24 23:13:55 字数 424 浏览 7 评论 0原文

我正在使用 JQUERY UI Accordion 模块:

<script type="text/javascript">
$(function() {
    $("#sidebar_column_accordion").accordion({
        fillSpace: true,
        icons: { 'header': 'ui-icon-plus', 'headerSelected': 'ui-icon-minus' }
    });
});
</script>

通过使用 fillSpace 选项,手风琴占据了我想要的窗口的整个高度。问题是它计算页面加载的高度,如果用户调整浏览器的大小,它不会调整...

有没有办法让手风琴在调整浏览器窗口大小时重新计算高度/大小?

谢谢

I'm using the JQUERY UI Accordion module:

<script type="text/javascript">
$(function() {
    $("#sidebar_column_accordion").accordion({
        fillSpace: true,
        icons: { 'header': 'ui-icon-plus', 'headerSelected': 'ui-icon-minus' }
    });
});
</script>

By using the fillSpace option, the accordion takes up the entire height of the window which I want. Problem is it calculate the height on page load, and if the user resizes their browser, it does not adjust...

Is there a way to have the accordion recalculate the height/size when the browser window is resized?

Thanks

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

伪装你 2024-08-31 23:13:55
$(window).resize(function(){
    $("#sidebar_column_accordion").accordion("resize");
});

在 jQuery UI 1.9 中,删除了调整大小方法。添加了刷新方法,该方法更加稳健,并且在这种情况下也适用。

$(window).resize(function(){
    $("#sidebar_column_accordion").accordion("refresh");
});
$(window).resize(function(){
    $("#sidebar_column_accordion").accordion("resize");
});

In jQuery UI 1.9 the resize method was removed. The refresh method was added which is more robust and will work in this case also.

$(window).resize(function(){
    $("#sidebar_column_accordion").accordion("refresh");
});
潦草背影 2024-08-31 23:13:55

貌似已经更新为“刷新”了

$(function() {
$( "#accordion" ).accordion({
heightStyle: "fill"
});
});
$(function() {
$( "#accordion-resizer" ).resizable({
minHeight: 140,
minWidth: 200,
resize: function() {
$( "#accordion" ).accordion( "refresh" );
}
});
});

It looks like this has been updated to "refresh"

$(function() {
$( "#accordion" ).accordion({
heightStyle: "fill"
});
});
$(function() {
$( "#accordion-resizer" ).resizable({
minHeight: 140,
minWidth: 200,
resize: function() {
$( "#accordion" ).accordion( "refresh" );
}
});
});
蓝眼泪 2024-08-31 23:13:55

在手风琴声明中设置 autoHeight: 'content'。这将使 div 使用内容的原生高度:

$('#accordion').accordion({
    autoHeight: 'content'
});

请参阅此处了解更多信息: http:// /jqueryui.com/accordion/#no-auto-height

Set autoHeight: 'content' in the accordion decalaration. This will make the div use the native height of the content:

$('#accordion').accordion({
    autoHeight: 'content'
});

See here for more info: http://jqueryui.com/accordion/#no-auto-height

忱杏 2024-08-31 23:13:55

发布的其他解决方案对我不起作用,尽管它们很接近。

使用 heightStyle:fill 定义手风琴,如下所示:

$("#sidebar_column_accordion").accordion({
                  heightStyle: "fill"
                });

创建一个函数来计算和设置高度。请注意,我必须同时执行这两项操作,设置高度,然后在手风琴上调用刷新。缺一不可。

function calculateHeight(){
  var height = $('#maincontent').height();  // Or whatever height you want
  $('#sidebar_column_accordion').height(height);
  $('#sidebar_column_accordion').accordion("refresh");
}

在页面加载和窗口大小调整时调用此函数。

calculateHeight();

$(window).resize(function () {
  calculateHeight();
});

The other solutions posted did not work for me, though they were close.

Define your accordion using heightStyle:fill, like so:

$("#sidebar_column_accordion").accordion({
                  heightStyle: "fill"
                });

Create a function to calculate and set the height. Note that I had to do both, set the height and then call refresh on the accordion. One won't work without the other.

function calculateHeight(){
  var height = $('#maincontent').height();  // Or whatever height you want
  $('#sidebar_column_accordion').height(height);
  $('#sidebar_column_accordion').accordion("refresh");
}

Call this function on both page load and window resize.

calculateHeight();

$(window).resize(function () {
  calculateHeight();
});
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文