Bugs in resizing and calculating height

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
<style type="text/css">

body {
    text-align: center;
}

#prob {
    background-color: #F00;
    width: 300px;
    text-align: center;
    line-height: 200px;
    display: inline-block;
    vertical-align: middle;
}

#prob img {
    width: 200px;
    height: 150px;
    display: inline;
    vertical-align: middle;
}


</style>
<script type="text/javascript" src="http://code.jquery.com/jquery-1.6.2.js"></script>
<script type="text/javascript">

$(document).ready(function(){

    var img = new Image();
    img.src = 'http://galerijauspomena.net76.net/images/10042011744.jpg';

    var div = $("#prob").get()[0];
    alert($(window).height()); // Initial height is shown slightly larger than page size
    document.getElementById("cont").style.lineHeight = $(document).height() + 'px';

    $(window).resize(
        function(){
            alert($(document).height()); // The height displayed after resize remains bigger, and Firefox freezes on resize!
            document.getElementById("cont").style.lineHeight = $(document).height() + 'px';
        }
    );
    div.appendChild(img);

});
</script>
</head>
<body>
<div id="cont">&nbsp; <!-- nbsp in order to line-height to work. Is it any way without it? -->
<div id="prob">&nbsp;</div>
</div>
</body>
</html>

Upon resizing the window, I noticed that the calculated height always appears larger, regardless of direction. Could this be due to a mistake in my code?

In addition, Firefox becomes unresponsive during resizing...

Answer №1

If my comprehension is correct, you are aiming to utilize $(window).height() instead of document. The issue lies in the fact that raising the line-height would lead to an increase in the document's size, consequently causing a continuous loop of escalating line-height and document size, resulting in perpetual growth.

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

Why isn't $.post functioning properly in any instance?

I've been experiencing issues with my $.post calls throughout my code. Despite not sending requests to different domains, everything is localhosted. My Mac OS X 10.8 automatically defined my localhost alias as ramon.local, and I'm trying to make ...

How to position two distinct elements within a Bootstrap 5 accordion button

I am currently working with Bootstrap 5 and facing a challenge in aligning a <p> tag and a <span> to the left and right, respectively. Despite trying various approaches, I am unable to achieve the desired outcome of having them move in opposite ...

Trimming whitespace from strings within HTML tag attributes can be achieved using various methods

I have been reviewing the .cshtml pages of a website with the aim of adding ID attributes to various divisions and elements for testing purposes. These pages utilize AngularJS, and many of the elements I need to add ID attributes to are part of a list tha ...

I'm in the process of constructing a create-next-app and I need to retrieve data from a web API. However, I'm unsure of the best place to securely store the API key

I am working on building a create-next-app that will retrieve data from the News Catcher API and display it within my application. I have obtained an API key to access the News Catcher API. However, I am unsure of where to securely store the API key and h ...

Attempting to retrieve the key of an object nested within a JSON structure

I'm trying to extract all the key names from a JSON object, but I seem to be missing some when using the Object.keys method: var myJSON = [ { "Employees_Name": "Bill Sanders", "Work_plan_during_my_absence": "Work from home", ...

JavaScript click event that triggers page scrolling and also executes a separate function

Currently in the process of developing a simple pricing calculator using HTML, CSS, and JavaScript. The user is presented with various questions that can be answered by clicking corresponding buttons for each response. All elements are contained within a s ...

Using jQuery to verify a CSS property of an element upon window resizing

Is it possible to include a window resize function in this code? jQuery(document).ready(function($){ var $MyDiv1 = $('#mydiv1'); if ($MyDiv1.length && $MyDiv1.css('position') == 'fixed') { ...

Display the contents of an HTML Object tag without relying on any external packages

Is there a way to print a PDF without opening it in a new tab? In my project, I have embedded a PDF using the HTML Object tag: <> <object id="documentObject" data={fileSrc} type={fileType} height="100%" width="100%" ...

``In a jade view, navigating through JavaScript object properties leads to the addition of quotation marks around strings

Utilizing the npm module traverse to filter data from mongodb / mongoose has been quite helpful for me. Here is an example of the kind of data I might receive: [ { rating: 5, title: { da: 'Web udvikling', en: 'Web Development' } } ...

The flow of browsing the web and executing scripts in a web browser

I'm really struggling to grasp the logic behind this function I'm working on. public void PortalLogin(AutoResetEvent signal) { // Navigate to portal string portalUrl = "website_name"; ...

Attempting to develop a straightforward JavaScript presentation display

The slideshow will cycle through six images named 1.jpg, 2.jpg, 3.jpg, 4.jpg, 5.jpg, and 6.jpg var showarray = ["1.jpg","2.jpg","3.jpg","4.jpg","5.jpg","6.jpg"]; var i = 0; for( i = 0; i < 6; i++) { // Is there a way to pause the script for two ...

Our JSON array property is not being parsed correctly by AngularJS

Upon receiving our GET request, the response is as follows: { "access_token": "pi7ID4bsZIC9yN ... 76gnblw", "token_type": "bearer", "expires_in": 1209599, "userName": "super0", "userRoles": "["member", "admin"]", ".issued": "Tue, ...

What is the best way to create a dropdown menu within an iframe that appears on top of all other frames?

The code snippet below is from my frameset.jsp file: </head> <iframe width="100%" src="mail_frame.html"></iframe> <iframe width="105px" height="100%" src="sidenav.html" id="leftnav" name="leftnav" ></iframe> ...

Enabling communication between JavaScript and PHP and vice versa

I am currently working on developing a Firefox plug-in with the purpose of gathering all the domains from the links located on the current site and showcasing their respective IP addresses. In order to achieve this, I have written JavaScript code that incl ...

Currently working on developing a Connect Four game and encountering an issue with the checkWin() function. It seems to be malfunctioning

Apologies in advance for adding to the flood of similar posts, but I believe my issue is quite straightforward. The current function under consideration, checkWin(), is not yet complete, but it operates on a list of columns containing jQuery objects and i ...

Issue with JQM popup functionality in Firefox browser

I am currently utilizing JQM 1.3.1 and have a webpage featuring various popups located at the bottom of the page: <div data-role="page" data-title="Strategic Plans"> <div data-role="content" id="capbPlans" data-bind="cafeLiveScroll: { callbac ...

One individual accessing another user's information

On my website, I store each user's TenantID in a cookie. Recently, I encountered a strange issue where if one user accessed the site on one computer and another user accessed it on a different computer, refreshing both browsers simultaneously would re ...

Does the "too much recursion error" result from the if clause?

Before I send my form data to a PHP script, I am performing a jQuery check: $(document).ready(function(){ $("#submit").submit(function(e){ var vari1 = $("#inputhidden1").val(); var vari2 = $("#inputhidden2").val(); if(vari1 == 1) { ...

How to properly format an HTML input box for numeric entry and ensure correct formatting of the minus sign

I need assistance with formatting an HTML text input box to only accept numeric values using JavaScript. Specifically, the input should allow digits, a minus sign, or a dot/comma (which will be converted to a dot). However, I want to prevent multiple conse ...

set ajax url dynamically according to the selected option value

My form features a select box with three distinct choices <select id="tool" name="tool"> <option value="option1">Option1</option> <option value="option2">Option2</option> <option value="option3">Option3</ ...