Adjustable height and maximum height with overflow functionality

Currently, I am in the process of developing a task manager for my application and facing an obstacle when trying to calculate the height of a widget. My goal is to determine the maximum height (assuming a minimum height is already set) by subtracting a certain value from the window's height for the task widget. Subsequently, I aim to dynamically retrieve the actual height of the div element and if it matches the calculated max-height, apply changes to some CSS properties. To accomplish this, I am utilizing jQuery version 1.5.2. Here is the code snippet that I have implemented...

$(document).ready(function() {
//Obtain the height for #tasks
var tH = Math.round($(window).height() - 463);
$('#tasks').css('height', tH); //Set it as the max height
var ti = Math.round($("#tasks").height()); //Retrieve the actual height of #tasks

if(tH==ti){ // If the actual height of #tasks equals the max-height, then perform...
    //alert('true');
    $('.taskItems').css('width', '172px');
    $('.tT, .tD').css('width', '135px');
    console.debug(ti + ' ' + tH);
}else{
    alert(tH + ' ' + ti); 
    console.debug(ti + ' ' + tH);
}
});

This method works perfectly fine when the "alert('true')" executes first and "max-height" is modified to "height".

However, the functioning of the if statement halts once the alert is removed.

Furthermore, changing "

$("#tasks").css('height', tH)

to "

$("#tasks").css('max-height', tH)

results in significantly mismatched values, for instance, 78/130. The corresponding CSS styling is provided below...

#tasks {
    border:1px solid #D1D1D1;
    border-top:none;
    color:rgb(82,124,149);
    display:inline-block;
    font-size:12px;
    margin:0px 0px 0px 1px;
    overflow:auto;
    width:194px;
}

Any assistance on resolving this issue would be greatly appreciated. Thank you in advance.

Answer №1

Whenever the window is resized, I employ the following script:

jQuery(document).ready(function () {

    jQuery(window).resize(function () {
        //alert("window changed");
        resizeDivs();
    });
});

function resizeDivs() {
    var clientWidth = jQuery(window).width();
    var clientHeight = jQuery(window).height();
    var newHeight = 100;
    var newWidth = 100;

    var firstDatasegment = jQuery(".datasegment")[0];

    if (!jQuery(firstDatasegment).width()) {
        currentWidth = jQuery(firstDatasegment).clientWidth;
        newHeight = currentWidth - (currentWidth / 7);
        newWidth = currentWidth;
    }
    else {
        currentWidth = jQuery(firstDatasegment).width();
        newHeight = currentWidth - (currentWidth / 7);
        newWidth = currentWidth;
    }

    jQuery(".datasegment").height(newHeight);
    jQuery(".sidemenu").height(clientHeight);
    jQuery(".maindatacontent").height(clientHeight);
    jQuery(".text-glow").css("font-size", (clientWidth / 50) + "px");
    jQuery(".hovermenuicon .menudesc").not('.bucketText').css("font-size", (clientWidth / 50) + "px");
    jQuery("td.menudesc span:first-child").not('.bucketText').css("font-size", (clientWidth / 50) + "px");
    jQuery(".sidemenudesc").css("font-size", (clientWidth / 80) + "px");
    jQuery(".datavalue").css("font-size", (clientWidth / 80) + "px");
    jQuery(".mainmenuitem").css("font-size", (clientWidth / 50) + "px");
    jQuery(".qireportgridview table").css("font-size", (clientWidth / 80) + "px");
    jQuery(".scrolldivbig").height(clientHeight);
}

To provide assistance tailored to your needs, please share the basic HTML code required for this functionality to operate correctly. Once provided, I will adjust the code with a functional example.

Hope this helps!

Answer №2

  1. To set the height using $('').height(), you can also use it as a setter like this: $('#tasks').height(th);

  2. When using $('').css('height': myVal), remember to specify a unit (e.g. px). You are not currently doing that.

  3. Could you clarify what you mean by

If you comment out the alert, the if statement will no longer work as expected.

In your else-branch, there is no action taken when the alert is removed.

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

Is it possible to achieve seamless image transitions in Firefox like it does in Chrome?

To achieve the desired effect, you may need to use some javascript. Visit aditagarwal.com for more information. Styling with CSS: .images-wrapper{ position: fixed; left: 0; top: 80px; bottom: 0; width: 100%; height: 100vh; an ...

Interact with Datatable by clicking on the table cell or any links within the cell

When I am working with the datatable, I want to be able to determine whether a click inside the table was made on a link or a cell. <td> Here is some text - <a href="mylink.html">mylink</a> </td> Here is how I initialize my da ...

Tips for eliminating annoying white space on petite gadgets with css programming?

Having an issue with my static html page where I am seeing white space on the right side when checking responsiveness. I have tried multiple solutions found here on stack overflow, including adding the following code: I attempted to add this inline: html ...

The dropdown menu in AngularJS is unable to retrieve the selected index

Presently, I have a dropdown menu: <select class="form-control" name="timeSlot" ng-model="user.dateTimeSlot" ng-change="dateTimeChanged(user.dateTimeSlot)" ng-blur="blur29=true" required style="float: none; margin: 0 auto;"> ...

Order of operations during synchronous $.ajax request handling

I'm grappling with understanding how synchronous ajax calls impact the order of execution as I encounter some peculiar bugs. // (1) $.ajax({ async: false, url: url0, dataType: 'json', success: function(data) { // (2) }); / ...

How can I adjust the timeout or enhance my code for Excel Online's ExcelScript error regarding the Range getColumn function timing out?

I am struggling with a code that is supposed to scan through the "hello" sheet and remove any columns where the top cell contains the letter B: function main(workbook: ExcelScript.Workbook) { let ws = workbook.getWorksheet("hello"); let usedrange = ws ...

Control and manage AJAX POST requests in the controller

I'm currently working on implementing an ajax post request feature in my project. The goal is to have a button on my html page trigger a javascript event listener, which then initiates an ajax post request to receive some text data. However, I seem to ...

Converting a string to regular text in JavaScript (specifically in ReactJS)

When I fetch data from an API, sometimes there are special characters involved. For example, the object returned may look like this: { question : "In which year did the British television series &quot;The Bill&quot; end?" } If I save t ...

Converting a PHP timestamp to a jQuery-compatible format

Can someone help me find the equivalent function in jQuery that will give me a time format similar to this: date( 'Y-m-d\TH:i:sP'); //the output is like this. 2013-10-30T18:10:28+01:00 I am looking for this specific format in jQuery to use ...

Implementing a sorting mechanism for ajax data retrieval

Currently, I am using the code below to save HTML created with jQuery in a database and retrieve it later: $('div[read]').each(function(){ var kelas = $(this).attr('kelas'); $.post('admin.php',{kelas:kelas,id:id},func ...

Setting a bookmark feature in HTML using localStorage: A step-by-step guide

I'm working on a simple code that captures the text content of a dynamically updated <h1> element and stores it as a "bookmark" in localStorage. I want to enable users to save or delete the bookmark by clicking a button. Below is a basic version ...

Obtain document via Angular 2

Is it possible to use TypeScript to download an image that is already loaded? <div *ngIf="DisplayAttachmentImage" class="fixed-window-wrapper_dark"> <button class="btn btn-close-window" (wslClick)="HideAttachmentImage()"> & ...

Clearing a leaflet layer after a click event: Step-by-step guide

When working with my map, I attempt to toggle the layer's selection using a mouse click. Initially, my map looks like this: Upon clicking a layer, my goal is to highlight and select it: If I click on a previously selected layer again, I want to dese ...

Issue encountered with create-next-app during server launch

Encountering an error when attempting to boot immediately after using create-next-app. Opted for typescript with eslint, but still facing issues. Attempted without typescript, updated create-next-app, and reinstalled dependencies - unfortunately, the prob ...

Steps for removing the label associated with an input field in an HTML form

I attempted to use JQuery and JavaScript in order to modify the CSS of a label to make it greyed out, but unfortunately I have not been able to achieve this. The label is positioned next to a checkbox, and although I am able to disable the checkbox, I hav ...

Positioning CSS for a Responsive Button

Currently, I am working on making my modal responsive. However, I am encountering an issue with the positioning of the "SAVE" button. The button is not staying in the desired position but instead disappears. Below is the snippet of my HTML and CSS: .dele ...

Retrieve Header information when making a cross-domain AJAX request

I've been working on a way to validate image URLs by using an AJAX call to check if the image is still available. The challenge I'm facing is that the image server is on a different domain, so I included the crossDomain: true attribute in my AJAX ...

Modify every audio mixer for Windows

Currently working on developing software for Windows using typescript. Looking to modify the audio being played on Windows by utilizing the mixer for individual applications similar to the built-in Windows audio mixer. Came across a plugin called win-audi ...

The final thumbnail fails to appear in the visible display (react-responsive-carousel)

I am currently facing an issue with displaying a series of images using react-responsive-carousel. When the images exceed a certain size causing the thumbnail section to become scrollable, the last thumbnail is always out of view. Although I have impleme ...

Having trouble with Vue.js implementation of Bootstrap tab navigation?

I am currently working on a vue.js application that consists of 2 routed components. I recently attempted to integrate a bootstrap tab navigation into the first component, but unfortunately, the tab contents are not being properly displayed. <templat ...