The height of the container is not adjusted correctly after loading data via ajax which causes it to overlap with

My HTML code consists of a container with two columns (content and sidebar) and a footer. The content contains a horizontal list with li elements that are populated via ajax when the "Load More" button is pressed. I am using Bootstrap and testing on Chrome, Win7.

I have encountered two issues:

First: When loading data using the 'Load More' button via ajax, the container overlaps the footer because the container height does not adjust correctly. I'm struggling to find a solution for this problem.

Second: On page load, there is a script running that sets fixed heights for both the content and sidebars. This script seems to be affecting the height adjustment when new data is loaded via ajax. I believe setting the same height for two columns in Bootstrap should not require javascript. Is there a non-javascript solution for this issue?

A live example can be viewed on this page: (scroll down and press Load more button).

The Javascript code that appears to set the fixed height for columns with class .equalcol.

/**
 * Javascript-Equal-Height-Responsive-Rows
 * https://github.com/Sam152/Javascript-Equal-Height-Responsive-Rows
 */
(function(jQuery) {
    jQuery.fn.equalHeight = function() {
        var heights = [];
        jQuery.each(this, function(i, element) {
            jQueryelement = jQuery(element);
            var element_height;
            var includePadding = (jQueryelement.css('box-sizing') == 'border-box') || (jQueryelement.css('-moz-box-sizing') == 'border-box');
            if (includePadding) {
                element_height = jQueryelement.innerHeight();
            } else {
                element_height = jQueryelement.height();
            }
            heights.push(element_height);
        });
        this.height(Math.max.apply(window, heights));
        return this;
    };
    jQuery.fn.equalHeightGrid = function(columns) {
        var jQuerytiles = this;
        jQuerytiles.css('height', 'auto');
        for (var i = 0; i < jQuerytiles.length; i++) {
            if (i % columns === 0) {
                var row = jQuery(jQuerytiles[i]);
                for (var n = 1; n < columns; n++) {
                    row = row.add(jQuerytiles[i + n]);
                }
                row.equalHeight();
            }
        }
        return this;
    };
    jQuery.fn.detectGridColumns = function() {
        var offset = 0,
            cols = 0;
        this.each(function(i, elem) {
            var elem_offset = jQuery(elem).offset().top;
            if (offset === 0 || elem_offset == offset) {
                cols++;
                offset = elem_offset;
            } else {
                return false;
            }
        });
        return cols;
    };
    jQuery.fn.responsiveEqualHeightGrid = function() {
        var _this = this;

        function syncHeights() {
            var cols = _this.detectGridColumns();
            _this.equalHeightGrid(cols);
        }
        jQuery(window).bind('resize load', syncHeights);
        syncHeights();
        return this;
    };
})(jQuery);

jQuery(function(jQuery) {
    jQuery('.equalcol').responsiveEqualHeightGrid();
});

Main HTML markup:

 <div class="contents">
        <!-- Content Column Start -->
        <div class="custom-container front-container">
            <div class="row">

                <div class="front-page col-lg-9 col-md-12 col-sm-12 col-xs-12 equalcol conentsection">
                    <div id="pl-343">                        
                        <div class="panel-grid" id="pg-343-5">
                            <div class="panel-grid-cell" id="pgc-343-5-0">
                                <ul class="horizontal-list">
                                    <li class="post-2978 vmgallery type-vmgallery status-publish format-standard has-post-thumbnail hentry gallery_categories-dazadi-un-episki">
                                        <div class="col-md-7 col-sm-7 col-xs-7 horizontal-list-media">

                                        </div>
                                        <div class="col-md-5 col-sm-5 col-xs-5 info">

                                        </div>
                                        <div class="clearfix"></div>
                                    </li>
                                     ...
                                </ul>
                                <div class="loader" style="display: none;">
                                </div><button id="load_more_mix_homepage">Load more</button>
                            </div>
                        </div>
                    </div>
                </div>
                <!-- Dark Sidebar Start -->
                <div class="col-lg-3 col-md-6 col-sm-6 col-xs-12 equalcol blacksidebar">
                    ...
                   <div class="clearfix"></div>
                </div>
                <!-- Dark Sidebar End -->
            </div>
        </div>

    </div>
    <!-- Contents End -->
    <!-- Footer Start -->
    <footer class="style1">
        <div class="custom-container">

            <div class="row footerwidgets">               
                <div class="col-lg-3 col-md-6 col-sm-6 col-xs-12">

                </div>
                <div class="col-lg-6 col-md-12 col-sm-12 col-xs-12">                    
                </div>
            </div>
            <hr>
            <div class="row">
                <div class="col-lg-10 col-md-10 col-sm-9 .col-xs-9">                    
                </div>
                <div class="col-lg-2 col-md-2 col-sm-3 .col-xs-3">                    
                </div>
            </div>
        </div>
    </footer>

Answer №1

Oftentimes, the content may not display properly until all images have been loaded. It has been observed that when the images are cached, the issue does not occur. Fortunately, there are several ways to address this issue.

  • One solution is to set a timeout for approximately one second and then refresh the height.
  • Another option is to add a load listener to each image and adjust the height once they have all loaded.
  • An alternative approach is to define the image width and height attributes on the server side so that the img tag will occupy the correct amount of space even if the image hasn't fully loaded yet.
  • You can also establish a fixed height for the img element or its parent container.

In my personal view, the first method is both the simplest and the most reliable.

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

Utilizing Material UI tabs panel with customized CSS styling

Having trouble changing colors and CSS in the TAB PANEL using material-ui. Any tips or suggestions? :( It seems like useStyle and theme functions are not working as expected. I was able to modify other properties like scrollable, but colors seem to be fix ...

Innovative: Enhancing column width dynamically without compromising grid integrity

Currently, I am utilizing Bourbon's Neat library to structure my grid system. Within my code, I have the following setup: section { @include outer-container; aside { @include span-columns(3); } article { @include span-columns(9); } } The chal ...

"Implementing a seamless transition effect on two slideshows using jQuery's fadeslideshow

I currently have a homepage featuring a fadeslideshow with 5 slides. The fadeslideshow plugin being used can be found at http://plugins.jquery.com/project/fadeslideshow. On the homepage, there is also a menu bar with various menu items. When a user clicks ...

Sending KeyValuePair or IDictionary as payload to Web Api Controller using JavaScript

In my web api controller, I am trying to post two parameters: a flat int ID and an IDictionary (or similar equivalent). [HttpPost] public void DoStuff(int id, [FromBody]IDictionary<int, int> things) { } var things = new Array(); things.push({ 1: 10 ...

Issues with ng-show functionality occurring during the initialization of the webpage

While working on a webpage using HTML, CSS, and Angular.js, I encountered an issue where the page content would not display properly upon loading. The objective was to show selected content based on user choices from a dropdown menu. Although the filtering ...

jquery method for clearing input field values

I am facing an issue with the form where the company name field automatically loads a value, even though it is a required field. I simply want to clear the previous loaded value and allow the user to input their information. For example, if I previously e ...

disabling empty elements in a React JS JavaScript component

Currently, I am retrieving data from an API where users can post content up to 3 times. However, if a user has not posted three times, empty boxes with padding and background color will appear. I want to remove all elements that do not have any content wit ...

Tips for positioning two elements side by side in an li element without needing to clear each time

I'm struggling with a stacked list that involves floating an image (icon) alongside text. The constant need to clear after each list item is becoming cumbersome. Anyone have any suggestions for making this more streamlined and tidy? <ul> < ...

Encountering an issue with the autocomplete feature in the jQuery library where it is stating "this.source is not a function."

Here's the code snippet I'm working with: $.ajax({ type: "GET", url: "https://url.com", dataType: "json", success: function (data) { $("#search").autocomplete({ source: data, select: function (even ...

Submitting a form with multiple actions using Ajax

Is it possible to submit data from multiple forms on the same page to different API tables using AJAX for each form? I have one form that needs to write to one table and another form that needs to write to a different table. How can I achieve this with o ...

When attempting to process a JSON string with JQuery's parseJSON() method, no response or error is returned

I've spent some time searching on various forums to find a solution to my problem, but it seems that no one else has encountered it. I am retrieving a JSON string from a field in my MySQL table, which is in the following format: {"width":"10", "heig ...

Parsing text files with Highcharts

As a beginner in JavaScript and HighCharts, I am facing a simple problem that has me completely lost. My goal is to generate a scatter chart with three lines by reading data from a text file formatted like this: x y1 y2 y3 1.02 1.00 6.70 ...

JQuery: Issues with attaching .on handlers to dynamically added elements

I'm currently developing a comment system. Upon loading the page, users will see a box to create a new comment, along with existing comments that have reply buttons. Clicking on a reply button will duplicate and add the comment text box like this: $( ...

Arrangement of Axes in Google Graphs

I have a basic form where users can input data through drop-down selectors. There are 10 questions, each with a rating out of 10. The entered data is then used to generate a Google graph on the same page. Although the graph populates correctly, the axis ...

Trigger behavior when an HTML element is altered using AngularJS

I am currently developing an on-page JS application using Angular, which will be seamlessly integrated into various pages of our main website. The app is embedded on our page using the following code snippet: <div class="app-video-list" ng-app="videoL ...

Best Practices for Implementing the 960 CSS Clear Class

I'm puzzled by the necessity of using the clear class in the 960 css framework. Every time I remove a div with the clear class, everything seems to function properly. Can you explain to me the significance and purpose behind this class? ...

Python Flask form displaying 'None' instead of inputted value

I recently started working on my first Python application and I'm following a tutorial which you can find here. Currently, I'm facing an issue where the information I enter in the form is not displaying correctly on the webpage, specifically for ...

Determine the dynamic height of content in a TypeScript file

Could you please provide guidance on obtaining the height of the content within this particular div element? For example, I need to calculate the dynamic height of the content. code .html <div class="margin-top-47 margin-horizontal-10" #hel ...

Parsing of the module failed due to an unexpected character appearing when trying to insert a TTF file into the stylesheet

As a newcomer to Angular, I recently completed the tutorial and am now working on my first app. While trying to add an OTF file, everything went smoothly. However, when I made a change to my app.component.css file and included this code snippet: @font-fa ...

The issue arises when the ng-hide directive fails to function properly due to the presence of a custom directive with the terminal option

Below is the code for my button: <button ng-hide="todo === 'add'" confirm-click ng-click="delete()">Delete</button> This is the directive implementation: (function(app) { app.directive('confirmClick', function(){ ...