jQuery Masonry now renders "row blocks" as opposed to trying to fit elements into place

Have you ever heard of the jQuery masonry plugin? It's a great tool for placing images in "blocks" instead of trying to squeeze them into empty spaces. Take a look at this explanation:

But how can we minimize those pesky "voids"?

HTML:

<!-- This overlay has 100% height, no scroll bar and fixed position -->
<div class='overlay-container'>

  <!-- The inner container is scrollable: -->
  <div class='row' id='ms-container'>

    <!-- Masonry items... -->
    <div class='col-md-4 ms-item'>
      <div class='boxcontainer'>
        <img src="photo.png" />
        <h1>
          <a href='#'>
            activity_2
          </a>
        </h1>
      </div>
    </div>
   <!-- More items... -->

  </div>
</div>

JavaScript:

    var $container = $('#ms-container');

    $container.imagesLoaded(function() {
    $container.masonry({

        itemSelector: '.ms-item',
        columnWidth: '.ms-item',
        transitionDuration: 0.4

    });

    });

CSS:

.overlay-container {
    height: 100% !important; 
    position: absolute;
    top:0px;
    width: 58%;
    left: 30px;
    padding: 50px 10px 10px 10px;
    overflow-y: auto;
    overflow-x: hidden;
}

.boxcontainer {
    border:1px solid #ededed;
    background:#fff;
    font-size:13px;
    text-align:center;
    transition:border 500ms ease-out;
    border-bottom:medium double #ddd;
    position:relative;
    overflow:hidden;
}

Answer №1

I attempted to utilize masonry in a project alongside bootstrap 3, but ultimately decided to switch to Isotope as it proved to be much simpler and more user-friendly. I have created an example using your structure, which you can view here. It is crucial to pay attention to the 'relative container' in order to prevent any plugin-related issues.

HTML

<!-- this overlay has height 100%, no scroll and position fixed -->
<div class='overlay-container'>
  <div class="relative">
    <!-- the inner container is "scroll-able": -->
    <div class='row' id='ms-container'>

      <!-- masonry items... -->
      <div class='col-md-4 ms-item'>
        <div class='boxcontainer'>
          <img src="http://placehold.it/300x500" />
          <h1>
            <a href='#'>
              activity_2
            </a>
          </h1>
        </div>
      </div>

     <!-- more items... -->

    </div>

  </div>
</div>

CSS

.overlay-container {
    height: 100% !important; 
    position: absolute;
    top:0px;
    width: 58%;
    left: 30px;
    padding: 50px 10px 10px 10px;
    overflow-y: auto;
    overflow-x: hidden;
}

.boxcontainer {
    border:1px solid #ededed;
    background:#fff;
    font-size:13px;
    text-align:center;
    transition:border 500ms ease-out;
    border-bottom:medium double #ddd;
    position:relative;
    overflow:hidden;
}

.relative { position:relative; }

JavaScript

$("#ms-container.row").isotope({
    masonry: {
        columnWidth: ".col-md-4"
    },
    itemSelector: ".ms-item",
    percentPosition: !0,
    layoutMode: "masonry"
});

I hope this information proves helpful.

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

Display a modal when clicking on a bootstrap glyph icon

I tried following a tutorial on how to create a Bootstrap modal at https://www.w3schools.com/bootstrap/bootstrap_modal.asp However, I would like to use a glyph icon in the code snippet like this: <span class="glyphicon glyphicon-pencil" class="btn btn ...

What is the best way to manage horizontal scrolling using buttons?

I was hoping that when the button is clicked, the scroll would move in the direction of the click while holding down the button. Initially, it worked flawlessly, but suddenly it stopped functioning. export default function initCarousel() { const carous ...

Shadow box with arrow/bubble element using CSS

I am looking to add a box shadow around the outline of the bubble below. <div class=speech-bubble-dark></div> .speech-bubble-dark { position: absolute; background: #fff; box-shadow: 2px 2px 5px rgba(0, 0, 0, 0.2); border-radius: 0.4em; ...

Fetching Data Sequentially with a Delay using AJAX and jQuery in PHP

As a newcomer to Jquery, I am looking for a way to showcase data in a sequential manner using AJAX. Imagine there is a table called "DATA" in my database with a field named "info" containing multiple rows of information. info 1 2 3 4 5 My goal is to exh ...

Oops! The regular expression flag "ajax" in Javascript is not valid and is causing

This is my function: public ActionResult RetrieveData(int id) { string name = "Jane"; return Json( new {result=name}); } I'm attempting to fetch information from this function using the code below, but I keep getting errors. Could y ...

Using JavaScript to choose an option within an optgroup

Is there a way to automatically select the option in the optgroup when I choose a user from the select list? Here is an example of the select code: <select name="city"> <optgroup label="Zone 1"> <option value=" ...

Determine the varying height of a replicated object

Is it possible in jQuery to retrieve the height of a clone object before it gets appended to the body, without specifying width and height in CSS? <body> <style>.square {}</style> <script> jQuery(function($) { var o = $(".s ...

Delete a class that is not identified by the DOM

Currently, I'm developing an interactive map that triggers an overlay image to highlight the selected area. I am trying to dynamically add and remove classes from a div based on the highlighted area. Initially, I attempted using the starts with selec ...

Deactivating all HTML DOM elements except for those with a specific #id

Currently, my goal is to deactivate all elements on an html page while keeping certain elements active. $('body').find('*').attr('onclick',"return false;"); //Deactivating all elements // I am attempting to activate the eleme ...

What causes the CSS `resize` property to be inherited in Chrome browsers?

It was my understanding that elements do not inherit the resize property from their parent elements. However, I recently discovered that in Chromium they actually do: Here is a screenshot of Chromium's inspector: Check out this demo: http://jsfi ...

Failure to update labels within jQuery dialog triggered by async postback

My .aspx file contains the following elements: In my .aspx file: The update panel below includes a button that is used to open a dialog box. <asp:UpdatePanel ID="UpdatePanel" runat="server" UpdateMode="Conditional" ChildrenAsTriggers="true" RenderMod ...

Having trouble with jQuery variable assignments not working in Safari?

My jQuery 1.3.2 code is encountering issues with Safari 4 for reasons unknown to me. Even though all my javascript references are placed right before the closing <body> tag, I am facing difficulties with the following snippet: var status = $(' ...

Submitting a form using Ajax without needing to navigate away from the current page

I'm facing an issue with submitting the Ajax form to prevent the page from redirecting to another page. The script I've implemented is still directing to trolley1.php instead of staying on the current product page. The objective is to send the da ...

Troubles encountered when converting JSON data into JSONP

I'm having trouble getting data in jsonp format for use with phonegap. The code seems to be not working on the web browser and there are no errors showing up in the console. It's clear that something must be wrong with the code, but since I have ...

Having trouble reading the file using jQuery in Internet Explorer 8 and earlier versions due to its non-XML format (albeit resembling XML)

Currently, I am utilizing AJAX to load a KML file (which essentially functions as an XML file). The parsing works seamlessly in IE9, FF, and other browsers, but encounters issues in IE8. Although the data is retrieved, I face difficulties parsing it in jQu ...

Updating the innerHTML of a frameset

I have a unique challenge that involves loading the frameset of www.example.com/2.html when accessing www.example.com/en/test/page.html. Successfully accomplished this task. Now, after loading 2.html in the frameset, I want to modify ".html" to ".html" t ...

Can you provide instructions on how to use the jquery ajax post method to upload data to a MYSQL database

While I am familiar with performing a regular PHP post method where you specify the $conn variable containing the IP address and login details for the database, I find myself uncertain about how to achieve the same using jQuery AJAX post method. $.post( ur ...

Encountering a problematic JQuery Ajax request to a RESTful API

I am currently in the process of trying to authenticate against demo webservices that were developed by one of my colleagues. While Cross-origin resource sharing is allowed and functions perfectly when I attempt to call from the Advanced Rest Client plugin ...

The CSS transition will only activate when coupled with a `setTimeout` function

After using JavaScript to adjust the opacity of an element from 0 to 1, I expected it to instantly disappear and then slowly fade back in. However, nothing seems to happen as anticipated. Interestingly, if I insert a setTimeout function before applying th ...

Implementing beforeSend and complete in all instances of ajaxForm throughout the entire application as a universal

Is there a way to use the beforeSend and complete functions on all ajaxForms within a project without having to repeatedly insert the same code throughout the entire project? I have managed to achieve this by adding the following code for each form indivi ...