What is the best method for efficiently filtering DIVs in a masonry gallery? Can filtering be accomplished solely with plain jQuery code?

I want to create a dynamic gallery showcasing photos, CSS3 animations, HTML5 elements, and jQuery code snippets. Can someone help me with implementing filtering using plain jQuery? Here's the code snippet:

      <!-- Filter Starts -->
    <div class="container">
      <div class="row safezone">
        <ul class="filters">
          <li><a href="#" title="All">All</a></li>
          <li><a href="#" title="CSS3">CSS3</a></li>
          <li><a href="#" title="jQuery">jQuery</a></li>
          <li><a href="#" title="Mobile">Mobile</a></li>
          <li><a href="#" title="Photos">Photos</a></li>
          <li><a href="#" title="UI">User Interfaces</a></li>
          <li><a href="#" title="Wireframes">Wireframes</a></li>
          <li><a href="#" title="Others">Others</a></li>          
        </ul>
      </div>
    </div>
    <!-- Filter Ends -->

<div class="container">
  <div class="row">
  <!-- gal cont-->
  <div id="masonry">
    <div class="mitem">
      <h3>CSS3 Animation</h3>
      <p>Text underline animation on mouse hover.</p>
      <p class="textanim">“<a href="javascript:void();"><strong>True love is born</strong></a> from understanding.”</p>
    </div>
    <div class="mitem box">
      <h3>CSS3 Circles</h3>
      <div class="circle-text"><p>Circles with pure CSS3</p></div>
    </div>
    <div class="mitem box">jQuery</div>
    <div class="mitem box">Mobile</div>
    <div class="mitem box">jQuery</div>
    <div class="mitem box">Wireframes</div>
    <div class="mitem box">Other</div>
    <div class="mitem box">UI</div>
    <div class="mitem box">UI</div>

    <div class="mitem box"><img class="img-responsive img-thumbnail" src="http://lorempixel.com/400/200/sports" /></div>
    <div class="mitem box"><img class="img-responsive img-thumbnail" src="http://lorempixel.com/400/200/sports/Dummy-Text" /></div>      
    <div class="mitem box"><img class="img-responsive img-thumbnail" src="http://lorempixel.com/400/200" /></div>      


</div>
  <!-- /gal cont -->
  </div>
</div>



var container = document.querySelector('#masonry');
var msnry = new Masonry( container, {
  columnWidth: 220,
  itemSelector: '.mitem'
});



@import url('https://fonts.googleapis.com/css?family=Cinzel:400,700,900|Satisfy');
@import url("http://fonts.googleapis.com/css?family=Roboto+Slab:400,700,100%7CRoboto:400,700,300,100");

/* Syntaxes for quick reference
transition: <property> <duration> <timing-function> <delay>;

=============================== */

/**  Basic Page CSS **/
body {
  font-family: 'Roboto Slab', serif;
  font-family: Roboto, "Helvetica Neue", Helvetica, Arial, sans-serif;
  font-weight: 300;
  font-size: 2em;
}
body.playground { background-color: #EAEDF1;  }

h1, h2, h3, h4, h5, h6 {  
  font-family: 'Cinzel', serif, sans-serif; 
  font-weight: 400;
  margin: 0;
}
.safezone { padding-top: 80px;  }
.borders { border:1px solid  red; }

/* Masonry */
.mitem {
  width: 200px;
  float: left;
    font-size: .85em;
    background: #fff;
    padding: 1em;    
    /*box-shadow: 1px 1px 2px 1px #e3e3e3;*/
    margin-bottom: 2em;
    border-radius: 2px; 
}
.mitem img { border:none; padding: 0; margin: 0; border-radius: 2px; }
#masonry h3 { font-size: 0.9em; font-weight: 600; color: #2C77F8; text-align: center; border-bottom: 0px dotted #78A8FF; margin: 0 0 10px 0; }
/* /Masonry */

/* CSS3 Circles  */
.circle-text {
    width:150px;
}
.circle-text:after {
    content: "";
    display: block;
    width: 100%;
    height:0;
    padding-bottom: 100%;
    background: #4679BD; 
    -moz-border-radius: 50%; 
    -webkit-border-radius: 50%; 
    border-radius: 50%;
    /*background-image: linear-gradient(to right bottom, #22B009 0%, #4679BD 100%);*/
    box-shadow: 3px 4px 3px #ccc;
    background-image: linear-gradient(to right, #4facfe 0%, #00f2fe 100%);
}
.circle-text p {
    float:left;
    width:100%;
    padding-top:50%;
    line-height:1em;
    margin-top:-0.5em;
    text-align:center;
    color:white;
}
/* =====================  */

/* text underline animation on hover 
======================================*/
 p.textanim > a {
    position: relative;
    color: #f00;
    text-decoration: none;
  }

  p.textanim > a:hover {
    color: #f00;
    text-decoration: none;
  }
  p.textanim > a:before {
    content: "";
    position: absolute;
    width: 100%;
    height: 2px;
    bottom: 0;
    left: 0;
    background-color: #f00;
    visibility: hidden;
    -webkit-transform: scaleX(0);
    transform: scaleX(0);
    -webkit-transition: all 0.3s ease-in-out 0s;
    transition: all 0.3s ease-in-out 0s;
  }
  p.textanim > a:hover:before {
    visibility: visible;
    -webkit-transform: scaleX(1);
    transform: scaleX(1);
  }
 /* ========================================== */


 /* CSS3 Box enlarge on hover 
 ==============================*/
.box:hover {  
  box-shadow: 0 5px 10px rgba(0,0,0,0.2);
  transform: scale(1);
  border-radius: 4px;
  color: #111;
  transition: all 0.2s ease-in-out 0s;
}
 /* =================================== */


 /* Filters 
 ==============================*/
ul.filters { list-style: none; margin: 0 auto 2em auto; }
ul.filters li { display: inline-block; border-right: 1px dotted #aaa; padding-right: 1em; margin-right: 1em; }
ul.filters li:last-child { border-right: none; }
ul.filters li a { text-decoration: none; font-size: 0.8em; padding: 5px 10px; border-radius: 20px; }
ul.filters li a:hover { text-decoration: none; background-color: #0095DD; color: #fff; transition: all 0.2s ease-in-out 0s; }
 /* =================================== */ }
}
}
}

Check out the code on jsfiddle: https://jsfiddle.net/tosrisri/thqL2Lf1/2/

Answer №1

If you're comfortable with using plugins, consider incorporating the Isotope masonry plugin. This tool takes care of organizing and filtering for you, offering a range of powerful filtering options. Best of all, it's completely free!

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

Open window maximizing size

URL = "window.open('../GBY/Reports/ReportViewer.aspx?ReportParams=" + ReportParams + "&ReportName=" + ReportName + " ' , '_blank');"; ScriptManager.RegisterClientScriptBlock(this.Page, typeof(UpdatePanel), "OPEN_WINDOW ...

An HTML component with no styling or appearance

When using JavaScript to dynamically modify text on a web page, I am running into issues with the text not being inline with other elements such as texts and inputs. I've tried using <div> and <p> but they create new lines and other format ...

In my actions, when I make a call using async/await, it results in a Promise that is currently <pending>

Greetings! I am a newbie when it comes to making api calls and have recently started using axios to fetch a simple deck of cards. In my attempt to make a basic axios call, I noticed that when I log the response (res), I get the desired data. However, upon ...

Guide on verifying a checkbox exclusively for the selected item within a jQuery success function

I am in need of only checking the items with a true value from the controller using the jQuery success function. <script type="text/javascript> $("#Pid").change(function () { $.ajax({ url: '@Url.Action("ge ...

fade in and out twice (for beginners)

Jquery <script> //Code snippet $(document).ready(function(){ $(".team").click(function(){ $(".panel").fadeToggle("3000"); }); $(".team").click(function(){ $(".teamh").fadeToggle("3000"); }); }); </script> HTM ...

Changing the position of elements dynamically in Javascript by altering their absolute positioning

I am working on an HTML page that contains a div positioned absolutely. My goal is to use Javascript to dynamically move this div downward whenever some data preceding it is generated. I have been experimenting with the .css jQuery function but unfortunate ...

When utilizing Ionic with Angular, it is difficult to access the hardware back button on mobile devices that have buttons located within the display/screen

When trying to access the hardware back button in my app, I encountered an issue where I couldn't produce an alert message to the user before the app closed. After posting a question on Stack Overflow (link of the question) and receiving help from the ...

Unraveling AngularJS: Mastering the Art of Interpolating Interpol

Trying to interpolate a string retrieved from the database, such as "Users({{users_count || 0}})", poses a problem. Using {{}} or ng-bind for interpolation does not work properly. The HTML code written is {{data.usersCount}}, but instead of ren ...

Integrating the frontend (HTML, CSS, and JavaScript) with the backend (Express server)

I've been trying to figure out the best way to connect the frontend and backend of a website, but I can't seem to find any clear answers online. Let's say you have a backend API with an endpoint that deletes a user's account when req ...

Executing all middleware within an express route

Currently, I am in the process of constructing an API using express and have implemented multiple middleware functions in my routes. One of the endpoints I am working on is displayed below: Router.route('/:id/documents') .get([isAuthenticated, ...

How can I retrieve the parent scope in an Angular UI nested named view?

One of the challenges I faced in my application was dealing with nested views within several screens. After experimenting with different approaches, I discovered that creating modal dialog boxes and sliding panels as actual nested states with corresponding ...

Creating a responsive button group with four Bootstrap 4 buttons arranged in two rows

How can I create a responsive one button group in bootstrap 4 with four buttons, arranged in two rows? ...

Tips on improving a function that verifies the existence of an image used as a CSS background to output a boolean value

I have encountered a challenge while working on a react file-upload component. The issue at hand is relatively simple - I aim to display an icon corresponding to the file extension for each uploaded file. These icons are loaded through css as background im ...

Guide to creating a Discord bot that replies privately to users without other channel members being able to see the messages

As a newcomer to Discord, I am attempting to create a bot that will respond to user commands by sending a reply that only the user who issued the command can see. However, I am struggling to figure out how to implement this feature. Below is the source c ...

Implementing one-to-many data updates in ASP.NET MVC using jQuery dialogs

Imagine this situation: I am working on a view for creating orders. The view includes header information such as the customer's address, delivery mode, and more. Additionally, there is a grid that displays the list of products that the customer has or ...

Central button placed in a card footer using Bootstrap

I have a .card-footer with three buttons: <div class="card-footer"> <button class="btn btn-theme pull-left" type="button" id="toleft"><</button> <button class="btn btn-theme" type="button" id="more">+</button> ...

The file size exceeds the server's upload limit, despite making changes to the php.ini file

I've encountered a problem trying to upload an .OBJ file to the server, resulting in an 'Error 1' message. The uploaded file surpasses the upload_max_filesize directive specified in php.ini This error is detailed on this page - http://ph ...

The classification of rejected promises in Typescript

Is it possible to set the type of rejection for a promise? For example: const start = (): Promise<string> => { return new Promise((resolve, reject) => { if (someCondition) { resolve('correct!'); } else { ...

Condensed JQuery condition code for "if" statement

This piece of code is designed to sequentially display 10 questions and control the visibility of each question using the CSS class .hideme. It also sends metrics data to Google Analytics. Although it functions properly, I feel like the code is too leng ...

What is the best way to format a description list with bullet points?

I need to style a <dl> description list that is unordered, so I want bullets before each <dt>. Edit: Just to be clear, I have an unordered list of <dt>-<dd> pairs. They should look like one list item, with the <dt> having a b ...