Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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

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

like image 981
Kimi Avatar asked Dec 26 '22 13:12

Kimi


2 Answers

From the version 2.1.0, you can use height or contentHeight options and set their value to auto.

The height option refers to entire calendar's height (including header). The contentHeight option refers to calendar's content area height.

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.

Initialize the calendar as follows:

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

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

More info here:

  • https://fullcalendar.io/docs/display/height/
  • https://fullcalendar.io/docs/display/contentHeight/
like image 37
andreivictor Avatar answered Jan 10 '23 12:01

andreivictor


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:

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

like image 97
Inferpse Avatar answered Jan 10 '23 10:01

Inferpse