javascript 如何使 jQuery FullCalendar 的高度适合其内容?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/13862942/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-26 20:00:17  来源:igfitidea点击:

How to make jQuery FullCalendar's height fit its content?

javascriptjqueryfullcalendar

提问by Kimi

I want to get rid of the scrollbars in the calendar'sdiv in the agenda views (week and day) and only use browser's scrollbar if the calendar's content does not fit the browsers viewport.

我想摆脱议程视图(周和日)中日历div 中的滚动条,并且仅在日历的内容不适合浏览器视口时才使用浏览器的滚动条。

So I believe I need to adjust the calendar's height to make its contents fit. How can I achieve that?

所以我相信我需要调整日历的高度以使其内容适合。我怎样才能做到这一点?

回答by Inferpse

There's a getViewmethod which returns current active View. And this Viewhas its own method setHeight, so you can create a function like this:

有一种getView方法可以返回当前的活动视图。这View有它自己的方法setHeight,所以你可以创建一个这样的函数:

function resizeCalendar(calendarView) {
    if(calendarView.name === 'agendaWeek' || calendarView.name === 'agendaDay') {
        // if height is too big for these views, then scrollbars will be hidden
        calendarView.setHeight(9999);
    }
}

And call it when view changed:

并在视图更改时调用它:

$('#calendar').fullCalendar({
    viewDisplay: resizeCalendar,
    ...
});

Working JSFiddle

工作JSFiddle

回答by andreivictor

From the version 2.1.0, you can use heightor contentHeightoptions and set their value to auto.

从 2.1.0 版本开始,您可以使用heightcontentHeight选项并将其值设置为auto

The heightoption refers to entire calendar's height (including header). The contentHeightoption refers to calendar's content area height.

height选项是指整个日历的高度(包括标题)。该contentHeight选项是指日历的内容区域高度。

According to plugin's docs, a value of automeans that the view's contents will assume a natural height and no scrollbars will be used.

根据插件的文档,值为 ofauto意味着视图的内容将采用自然高度并且不会使用滚动条。

Initialize the calendar as follows:

初始化日历如下:

$('#calendar').fullCalendar({
    contentHeight: "auto",
    // .... other options here 
});

Fiddle here: https://jsfiddle.net/yj90oqzf/

在这里小提琴:https: //jsfiddle.net/yj90oqzf/

More info here:

更多信息在这里: