Alter the design when the height of a div is adjusted

On my webpage, I have multiple divs displayed in a masonry layout. The masonry effect works smoothly, but I am facing an issue with the divs expanding in height when users leave comments. The masonry layout does not automatically adjust to accommodate the increased div height.

These divs are reloaded using ajax.

 <script>
    $(document).ready(function() {
      var $container = $('#REATinsidEpoASttt78');
      $container.imagesLoaded(function(){
          $container.masonry({
              itemSelector : '.realFLOAtingPOSTSA',
              columnWidth : 350
          });
      });
    });
  </script>

The code snippet above sets up the masonry layout. Now, let's look at the div reloading functionality.

function formsubmitionbyajax(obj){
    var id=$(obj).attr("id");
    var currentform = $(obj);
    $('#COMMlo'+id).show();
    $.ajax({ type: 'post',
        url: 'home_formhandler1.php',
        data: currentform.serialize(),
        success: function(){
            $("#mainDIV"+id).load('home.php #mainDIV'+id);
        } 
    });
    return false;   
}

Here is a snippet of the HTML structure:

<div id="REATinsidEpoASttt78">
  <div class="realFLOAtingPOSTSA">
    <div id="mainDIVffrmMN<?=$THE_DTAinar['id']?>">
       content retrieved from the database...
    </div>
  </div>
</div>

I am looking for a solution to dynamically rearrange the divs whenever their height changes. Currently, I am using the following approach:

var container = document.querySelector('#REATinsidEpoASttt78');
var msnry = new Masonry( container, {
    columnWidth: 350
});
setTimeout(function () { msnry.layout();   }, 2000);

Although this method works, it introduces a 2-second delay in rearranging the divs. I am seeking a more efficient solution. Can anyone provide suggestions?

Answer №1

Implement the resize event method as shown below:

var container = document.querySelector('#REATinsidEpoASttt78');
var msnry = new Masonry( container, {
                 columnWidth: 350
           });
$('#REATinsidEpoASttt78').on('resize',function () {  
   msnry.layout();
});

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

"Encountering a problem with compression in Kafka while using the Node.js client with

I am currently utilizing the kafka-node library to consume data from Kafka. It appears that the data I am receiving is compressed with SNAPPY. How can I decompress this data once it has been retrieved? I attempted to use the node-snappy library for decompr ...

Is the Webpack vendors JS bundle in Vue CLI containing unlisted code that is not in the dependencies or package-lock.json file?

An information security auditing tool flagged an outdated library with known vulnerabilities in our webpack-bundled chunk-vendors.js file generated using Vue CLI: The library in question is YUI 2.9.0. It appears that this library is not fully included, a ...

Transmit information from the main directive to the subordinate directive

Hi everyone, I have a quick question.. I'm working on a directive that includes an ng-repeat and transclude, with several child directives inside it that need to inherit specific objects from each iteration... So far, I've only managed to achiev ...

Retrieving Docker logs from MongoDB for analysis

Storing logs from Docker into MongoDB using Fluentd has been a fairly simple setup. However, my current struggle lies in retrieving these logs in the correct order while also implementing pagination. The structure of a log document typically looks like th ...

Attempting to create a custom web user interface tree from the ground up

I noticed that yahoo ui uses div for each node in the tree structure. Is this the best practice, considering that every node, even the leaf nodes, are heavily nested with div, table, tr, and td elements? Is there a more efficient way to achieve the same re ...

I want to locate every child that appears after the <body> element, and extract the HTML of the element containing a specific class within it

It may sound a bit confusing at first, but essentially I have some dynamically generated HTML that resembles the following: <body> <div class="component" id="465a496s5498"> <div class="a-container"> <div class="random-div"> ...

Locate commas within quotation marks using regex and replace them with their corresponding HTML entity

When dealing with a string like this: "Hello, Tim" Land of the free, and home of the brave I want it to be transformed into: "Hello&#44; Tim" Land of the free, and home of the brave This should be a simple task, but I'm struggling to find th ...

Utilizing JQuery Ajax to dynamically replace elements using JQuery functions

My issue is as follows... I am using AJAX and jQuery to populate a form. When the user makes a selection from a dropdown menu, AJAX retrieves data based on the choice and populates the form with this data. Sometimes, new elements are created when the AJA ...

How can you override the selected classes for menu items in Material-UI using React.js?

Hey there! I'm facing an issue where I can't override the class that displays the correct styling when a menuItem is selected. Below is my code: <MenuItem component={Link} to="/Acceuil" className={{root:classes.menuItem ,selected:cla ...

Could the mechanism of an image carousel be considered a jQuery "template"?

My goal is to create a simple image slider using jQuery, but I want to learn from basic patterns like the 'slider' or 'accordion' without the added complexity of plugins and tutorials. I am looking for very basic jQuery patterns to stud ...

Node.js post request body is still showing as undefined despite using body-parser

Hello everyone, I am currently using Node.js to implement a Dialogflow chatbot. My goal is to extract parameters from an HTTP POST request. To achieve this, I utilized Postman and made sure to set the content type to JSON in the header. Below is the code f ...

What is the hierarchy of fields in package.json?

After submitting a pull request to a repository to include a typings field in the package.json file, the maintainer suggested the following modification: - "typings": "./src/index.d.ts", - "main": "./src/index.js" ...

Randomly selecting JavaScript with different likelihoods or percentages

I am currently running a Node.js process with setInterval that occurs every 100ms. Within this process, I have specific actions that I want to execute at varying intervals such as 2% of the time for action X and 10% of the time for action Y. Currently, my ...

Troubleshooting alignment problems with a responsive gallery (Bootstrap-gallery & justifyGallery)

Looking to showcase a gallery of images using jquery-justifyGallery and bootstrap-gallery. Want to display 4 images in a row, but running into issues when trying to display 5 images where the last image in the row ends up with a larger width. Bootstrap has ...

Turn off autocomplete feature to prevent interference while handling database information

My Kindo AutoComplete is nested within a helper function. Whenever I perform a search and select one of the AutoComplete results, it triggers a function that retrieves data from the source. The information takes some time to load and appear on the page. ...

Bug found in React Native when navigating between screens causing the screen size to shrink

Check out the image below. https://i.stack.imgur.com/t04Vv.png Issue: Whenever I switch to a new scene, the previous screen appears to shrink or move upwards. This behavior is not consistent with the usual user experience seen on Apple apps - any thought ...

using Ajax to dynamically populate a selection list in a Rails application

My menu is dynamic and I attempted to utilize the grouped_collection_select feature <%= f.grouped_collection_select :unit_id, Project.visible.order(:position), :units, :name, :id, :full_name, include_blank: true, class: 'items' %> However ...

Is there a way to transform this fixed alignment of divs, etc. into a responsive layout that automatically adjusts to different screen sizes? - Using HTML and CSS3

If you want to see the demo, you can check it out on JSFiddle by clicking on this link: JSFiddle Demo. This webpage utilizes Twitter's Bootstrap framework, which you can find more information about by visiting . When inspecting the stylesheet on JSF ...

Is there a way to convert time measurements like minutes, hours, or days into seconds in React and then pass that information to an

Currently, I am working on an application that allows users to select a frequency unit (like seconds, minutes, hours, or days) and input the corresponding value. The challenge arises when I need to convert this value into seconds before sending it to the ...

Showing the outcome of the AJAX call

I have searched extensively for information on how to use AJAX, but I have been unable to find a resource that clearly explains the concept and its workings. When I send an AJAX request to a PHP file using the code below, I can see the response in Mozilla ...