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
How to make jQuery FullCalendar's height fit its content?
提问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 getView
method which returns current active View. And this View
has 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 height
or contentHeight
options and set their value to auto
.
从 2.1.0 版本开始,您可以使用height
或contentHeight
选项并将其值设置为auto
。
The height
option refers to entire calendar's height (including header).
The contentHeight
option refers to calendar's content area height.
该height
选项是指整个日历的高度(包括标题)。该contentHeight
选项是指日历的内容区域高度。
According to plugin's docs, a value of auto
means 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:
更多信息在这里: