Adjust the height of Fullcalendar when the window is resized to maintain the aspect ratio as it shrinks

I am having trouble adjusting the height of an FC (fullcalendar) within a div. My goal is to have the FC completely fill the div without overflowing. Despite setting the height attribute during initialization, the FC's height does not resize properly, resulting in a narrow and unreadable calendar. I have tried dynamically adjusting the height using jQuery and CSS, with no success. How can I resize the FC while maintaining its aspect ratio for readability?

P.S: I have reviewed the documentation and attempted various methods to adjust the FC's height, but I am still unable to achieve the desired result.

$(document).ready(function() {

  //----------SCHEDULE INITs----------
  $('#schedule_1').fullCalendar({
    theme: false,
    // contentHeight: $('#scheduleDiv').height(),
    contentHeight: "auto",
    //height: "auto",
    defaultDate: '2000-01-03',
    defaultView: 'agendaWeek',
    columnFormat: 'dddd',
    allDaySlot: false,
    minTime: "07:00:00",
    maxTime: "21:00:00",
    navLinks: false,
    editable: false,
    eventLimit: true,
    header: false
  });


  $('#schedule_1').fullCalendar('option', 'height', 100); //Seems to have no effect...
});
html {
  position: relative;
  min-height: 100%;
}

body {
  background-color: #FCFDFE;
  min-height: 100%;
  margin-bottom: 60px;
  overflow-y: scroll;
}
<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="utf-8" />
  <meta name="viewport" content="width=device-width, initial-scale=1.0">

  <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
  <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js" integrity="sha384-Tc5IQib027qvyjSMfHjOMaLkfuWVxZxUPnCJA7l2mCWNIpG9mGCD8wGNIcPD7Txa" crossorigin="anonymous"></script>
  <script src="//cdnjs.cloudflare.com/ajax/libs/moment.js/2.10.3/moment.min.js"></script>
  <script src="https://cdnjs.cloudflare.com/ajax/libs/fullcalendar/3.5.1/fullcalendar.js"></script>
  <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/fullcalendar/3.5.1/fullcalendar.min.css">
  <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" integrity="sha384-BVYiiSIFeK1dGmJRAkycuHAHRg32OmUcww7on3RYdg4Va+PmSTsz/K68vbdEjh4u" crossorigin="anonymous">
</head>

<body>
  <div class="container-fluid" id="main">

    <div class="col-md-8">
      <div id="schedule_1"></div>
    </div>


    <div class="col-md-4">
      <p>Second Column!</p>
    </div>

  </div>

</body>

</html>

Answer №1

The reason for this issue is the contentHeight being set to "auto".

$('#schedule_1').fullCalendar('option', 'height', 100); //Does not seem to make a difference...

As a result, the code you are attempting to set in the line above is not reflected.

Here is a link for your reference: https://jsfiddle.net/9vn3g8xa/

Answer №2

In addressing your specific concern regarding height, attempting to adjust the height of the calendar to be less than its computed content height is inherently illogical.

To achieve the desired height reduction, ensure that the contentHeight option is set to an equal or lesser value, as shown below:

$(document).ready(function() {

  //----------SCHEDULE INITs----------
  $('#schedule_1').fullCalendar({
    theme: false,
    defaultDate: '2000-01-03',
    defaultView: 'agendaWeek',
    columnFormat: 'dddd',
    allDaySlot: false,
    minTime: "07:00:00",
    maxTime: "21:00:00",
    navLinks: false,
    editable: false,
    eventLimit: true,
    header: false,
    height: 100,
    contentHeight: 100
  });
});

html {
  position: relative;
  min-height: 100%;
}

body {
  background-color: #FCFDFE;
  min-height: 100%;
  margin-bottom: 60px;
  overflow-y: scroll;
}
<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="utf-8" />
  <meta name="viewport" content="width=device-width, initial-scale=1.0">

  <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
  <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js" integrity="sha384-Tc5IQib027qvyjSMfHjOMaLkfuWVxZxUPnCJA7l2mCWNIpG9mGCD8wGNIcPD7Txa" crossorigin="anonymous"></script>
  <script src="//cdnjs.cloudflare.com/ajax/libs/moment.js/2.10.3/moment.min.js"></script>
  <script src="https://cdnjs.cloudflare.com/ajax/libs/fullcalendar/3.5.1/fullcalendar.js"></script>
  <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/fullcalendar/3.5.1/fullcalendar.min.css">
  <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" integrity="sha384-BVYiiSIFeK1dGmJRAkycuHAHRg32OmUcww7on3RYdg4Va+PmSTsz/K68vbdEjh4u" crossorigin="anonymous">
</head>

<body>
  <div class="container-fluid" id="main">

    <div class="col-md-8">
      <div id="schedule_1"></div>
    </div>

    <div class="col-md-4">
      <p>Second Column!</p>
    </div>

  </div>

</body>

</html>

Refer to https://fullcalendar.io/docs/display/contentHeight/ for more information.

Regarding the remainder of your query about adjusting the FC's size while maintaining its aspect ratio to prevent illegibility, further details are required. The scenario you envision may result in unreadability if the width decreases significantly. Utilizing the aspectRatio option allows for better control rather than setting a fixed height. Providing screenshots and specifics of the issue will facilitate tailored suggestions for resolution.

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Can you help me with compiling Twitter Bootstrap 3.0 on my Windows 8?

Can anyone guide me on compiling Twitter Bootstrap using Less on a Windows machine? I tried following a tutorial but ran into issues with installing lessc (it was not in the npm registry). Also, the tutorial was for BS2 and not 3.0 which made me skeptical ...

What is the best way to uppercase each element in an array using only a while loop in plain ECMAScript 5?

Struggling with a simple exercise that requires converting names to uppercase and passing them to an empty array using only while loop(s) in plain JavaScript: var names = ['rob', 'dwayne', 'james', 'larry', 'st ...

Having trouble deleting files in PHP?

I am presenting an HTML form below: <form action='delete.php' method='POST'> <table> <div class = '.table'> <?php $dir = '../uploads/store/'; $new ...

Guide to using vite-plugin-rewrite-all in conjunction with Quasar for Vue 3 - or alternative method to enable periods in paths

Encountering a 404 error when using quasar+vite in vueRouterMode: 'history' mode with paths containing a period/dot in the id? This issue has been discussed in various places: https://github.com/vitejs/vite/issues/2415 https://github.com/vitejs/ ...

Using knex.js to pipe data to an express server

I'm encountering an issue with knex.js and express. Here is the code snippet in question: userRouter.get('/:userId', function (req, res) { DB('users').where({ id: req.params.userId }).first('name').pipe(res); }); ...

The Web Browser is organizing CSS elements in an alphabetized sequence

map.css({ 'zoom': zoom, 'left': map.width()/(2*zoom) - (point[0]/100)*map.width(), 'top': map.height()/(2*zoom) - (point[1]/100)*map.height() Upon observation, it appears that Chrome adjusts the map zoom first be ...

Tips for Making Your Popup Window Stand Out

Looking to design a unique pop-up window featuring three tree-style radio buttons and a single submit button. Upon selecting one of the radio buttons, the chosen value should be recorded in the parent window. ...

The jQuery autocomplete feature grows to cover the entire display

I am currently working on integrating an autocomplete feature into a search bar. However, when I start typing in the text, the autocomplete box expands to take up my entire screen. Is there a way for me to adjust the size of the popup box that appears? Sin ...

Passing User Authentication State from Express/Passport to a React Client: A Step-by-Step Guide

I want to pass a basic boolean value const isLoggedIn = true; (provided by Passport) from my Express backend to my React frontend. I'm looking for an alternative to embedding it in the HTML through a templating engine. This seems like a common req ...

Clickable link that directs to a particular tab on a webpage (cbpFWTabs)

I have been utilizing tabs from the codrops Tab Styles Inspiration and I am looking for a way to open specific tabs using URLs. For instance, if I wanted to open tab3, I could link it as www.google.com/index#tab3. Below is the code I am currently using: ...

HTML5 database error: Uncaught TypeError due to illegal invocation

When I test the code below in Chrome, I encounter an error: var db = openDatabase('foo', 1, 'foo', 1111); var sql = function(callback){ db.transaction(function(tx){ callback(tx.executeSql); }); }; sql(function(query){ ...

Migrating from PHP/MySQL to PDO: A Smooth Transition

I am a beginner in PHP/MySQL and I have some queries. I was watching a YouTube tutorial on creating a basic dynamic website that retrieves data from a MySQL database and displays it on a single PHP index page. I followed the tutorial up to the point wher ...

Learn the process of invoking componentDidMount each time you switch between ListItems in React

After initializing the widget component to load various charts, it works correctly. However, when switching to another ListItem, the componentDidMount does not load the required data. This data is essential for the component to function properly. I noticed ...

Testing a function within a React functional component using jest.spyOn with React Testing Library can be accomplished with the following steps:

I'm currently working on a React component and I'm facing an issue with unit testing using React Testing Library. Specifically, I'm having trouble testing the handleClick function of the TestComponent using jest.spyOn(). Can anyone provide s ...

Tips for utilizing innerHeight for a div during both window loading and resizing tasks?

I'm currently working on calculating the top/bottom padding of a div (.content) based on its height, and updating it upon loading and resizing the window. The goal is to have it centered nicely next to another div (.character) positioned beside it. I ...

What methods can be used to prevent accessing 'res' after the resolution of getServerSideProps?

While working on my nextJS application, I encountered an error in the page file: warn - You should not access 'res' after getServerSideProps resolves. Read more: https://nextjs.org/docs/messages/gssp-no-mutating-res I tried reading the provided ...

Challenges with Loading JSON Dynamically in Next.js using an NPM Package

In my TypeScript project, I have implemented a functionality where a json configuration file is dynamically loaded based on an enum value passed as a parameter to the getInstance function in my PlatformConfigurationFactory file. public static async getIn ...

Is it possible to showcase a dropdown list within a constantly changing table?

I have a table code snippet that I need help with <fieldset class="tabular"><legend><%= l(:redmine_taskjuggler) %></legend> <%= labelled_fields_for(@issue) do |f| %> <div id="taskjuggler" class="attributes"> <div cl ...

Events in the backbone view fail to trigger after a re-render

For some reason, I am struggling to get mouse events to work on my backbone view after it is re-rendered. It seems like the only solution is to use a rather convoluted jQuery statement: $("a").die().unbind().live("mousedown",this.switchtabs); I initially ...

Unable to retrieve Java variable in JavaScript

Seeking guidance on how to retrieve Json data stored in a Java variable using JavaScript. Instead of accessing the data, the html source is displayed. Java: Gson gson = new Gson(); String json = gson.toJson(obj); request.setAttribute("gsonData", gson) ...