Combining photos seamlessly and bringing them to life through animation upon window loading

My main goal is to seamlessly fit the images together, but I'm struggling to achieve this. I tried using masonry, but unfortunately it didn't work for me. All I want is to tightly pack the divs together. For instance, in my fiddle example, I would like the bottom left and right cat images to move up.

Additionally, I am interested in adding an animation effect when the user first views the images on page load, similar to this example:

Do you have any suggestions on how to accomplish either of these tasks?

Fiddle: https://jsfiddle.net/jzhang172/0jL2dyg1/

.grid{
            display:flex;
            flex-direction:row;
            justify-content:center;
            max-width:500px;
            flex-wrap:wrap;
        }

        .grid-item{
          height:150px;
          width:150px;
          overflow:hidden;

        }
        .grid-item img{
          height:100%;
        }
        .item-2{
          height:300px;
        }
<div class="grid">
          <div class="grid-item"><img src="http://www.keenthemes.com/preview/metronic/theme/assets/global/plugins/jcrop/demos/demo_files/image1.jpg"></div>
          <div class="grid-item item-2"><img src="http://www.joomlaworks.net/images/demos/galleries/abstract/7.jpg"></div>
          <div class="grid-item"><img src="http://www.online-image-editor.com//styles/2014/images/example_image.png"></div>
          <div class="grid-item"><img src="http://www.online-image-editor.com//styles/2014/images/example_image.png"></div>
          <div class="grid-item"><img src="http://www.online-image-editor.com//styles/2014/images/example_image.png"></div>
          <div class="grid-item"><img src="http://www.online-image-editor.com//styles/2014/images/example_image.png"></div>
        </div>

Answer №1

I found this great tutorial on a site called css-tricks and adapted it using your images!

HTML

<section id="photo-gallery">
  <img src="http://www.keenthemes.com/preview/metronic/theme/assets/global/plugins/jcrop/demos/demo_files/image1.jpg">
  <img src="http://www.joomlaworks.net/images/demos/galleries/abstract/7.jpg">
  <img src="http://www.online-image-editor.com//styles/2014/images/example_image.png">
  <img src="http://www.online-image-editor.com//styles/2014/images/example_image.png">
  <img src="http://www.online-image-editor.com//styles/2014/images/example_image.png">
  <img src="http://www.online-image-editor.com//styles/2014/images/example_image.png">
</section>

CSS

#photo-gallery {
  /* Eliminate any vertical gaps */
  line-height: 0;

  -webkit-column-count: 5;
  -webkit-column-gap:   0px;
  -moz-column-count:    5;
  -moz-column-gap:      0px;
  column-count:         5;
  column-gap:           0px;  
}

#photo-gallery img {
  /* Ensure all images fill the space */
  width: 100% !important;
  height: auto !important;
}

@media (max-width: 1200px) {
  #photo-gallery {
  -moz-column-count:    4;
  -webkit-column-count: 4;
  column-count:         4;
  }
}
@media (max-width: 1000px) {
  #photo-gallery {
  -moz-column-count:    3;
  -webkit-column-count: 3;
  column-count:         3;
  }
}
@media (max-width: 800px) {
  #photo-gallery {
  -moz-column-count:    2;
  -webkit-column-count: 2;
  column-count:         2;
  }
}
@media (max-width: 400px) {
  #photo-gallery {
  -moz-column-count:    1;
  -webkit-column-count: 1;
  column-count:         1;
  }
}

Does this meet your needs? Check out the live example in this fiddle.

Answer №2

Simply:

1- delete the item-2 class.

2- include margin-bottom and margin-left properties to the grid-item class:

.grid-item{
  height:150px;
  width:150px;
  overflow:hidden;
  margin-bottom: 15px;
  margin-left: 15px;
}

View this example.

Answer №3

you may want to consider implementing this example using the Masonry library:

<style type="text/css">
.grid {
  max-width:500px;
}
.grid:after {
  content: '';
  display: block;
  clear: both;
}
.grid-item{
  height:100px;
  width: 100px;
  overflow:hidden;
}
.grid-sizer{
  width: 100px;
}
.item-2{
  height:200px;
}
.item-3{
  width: 300px;
}
.item-4{
  width: 400px;
}
.grid-item img{
  height:100%;
  width: 100%;
}
</style>
<div class="grid">
    <div class="grid-sizer"></div>
    <div class="grid-item"><img src="http://www.keenthemes.com/preview/metronic/theme/assets/global/plugins/jcrop/demos/demo_files/image1.jpg"></div>
    <div class="grid-item item-2"><img src="http://www.online-image-editor.com//styles/2014/images/example_image.png"></div>
    <div class="grid-item"><img src="http://www.joomlaworks.net/images/demos/galleries/abstract/7.jpg"></div>
    <div class="grid-item"><img src="http://www.online-image-editor.com//styles/2014/images/example_image.png"></div>
    <div class="grid-item"><img src="http://www.online-image-editor.com//styles/2014/images/example_image.png"></div>
    <div class="grid-item"><img src="http://www.online-image-editor.com//styles/2014/images/example_image.png"></div>
    <div class="grid-item item-3"><img src="http://www.online-image-editor.com//styles/2014/images/example_image.png"></div>
    <div class="grid-item item-4"><img src="http://www.online-image-editor.com//styles/2014/images/example_image.png"></div>
    <div class="grid-item"><img src="http://www.keenthemes.com/preview/metronic/theme/assets/global/plugins/jcrop/demos/demo_files/image1.jpg"></div>
    <div class="grid-item"><img src="http://www.keenthemes.com/preview/metronic/theme/assets/global/plugins/jcrop/demos/demo_files/image1.jpg"></div>
    <div class="grid-item"><img src="http://www.keenthemes.com/preview/metronic/theme/assets/global/plugins/jcrop/demos/demo_files/image1.jpg"></div>
</div>

<script type="text/javascript" src="jquery.1.11.3.min.js"></script>
<script type="text/javascript" src="bootstrap.min.js"></script>
<script src="masonry.pkgd.min.js"></script>
<script type="text/javascript">
$('.grid').masonry({
  itemSelector: '.grid-item',
  columnWidth: '.grid-sizer'
}).masonry("layout");
</script>

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

JavaScript code does not seem to be functioning properly on my computer, but it works perfectly fine on

While the code functions perfectly in JSFiddle, it seems to fail when I try to implement it in an HTML file. Despite my efforts, I am unable to pinpoint the source of the issue. If you'd like to view the working version, here is the Fiddle demo. Bel ...

Tips on displaying only the child of the current list item while hiding the children of other list items

I have multiple nested ul elements on my page that are displayed using the following jQuery code. jQuery $("li").click(function(){ $(this).children("ul").show("slow"); }); However, I want to only display one nested ul at a time. This means that when ...

Exporting Data and Utilizing a Steady Data Table

I have incorporated the Fixed Data Grid into my latest project. https://facebook.github.io/fixed-data-table/example-sort.html My goal is to generate csv and pdf reports from the data displayed on the grid. Could you please advise me on how to export gri ...

Creating a sort button in HTML that can efficiently sort various divs within a table is a useful tool for enhancing user experience

My HTML table is populated with various <td> elements. How can I arrange these divs based on IMDb rating, TomatoMeter, etc... [ CSS code is not provided below ] <table> <tr class="row"> <td class="column"> <br> ...

A Vue component library devoid of bundled dependencies or the need for compiling SCSS files

My current challenge involves the task of finding a way to publish our team's component library. These components are intended to be used by various internal applications within our organization. I have specific requirements: The library must be acc ...

Tips for avoiding page reload when submitting a form with form.submit() in ReactJs

Is there a way to avoid the page from refreshing when triggering form submission programmatically in ReactJS? I have attempted to use this block of code: const myForm = () => <form onBlur={(e) => { if(!e.relatedTa ...

Setting up the CSS loader in a Vue.js project using webpack

I am currently working on a new vue-cli project and have successfully installed the Pure.CSS framework using npm install purecss --save. However, I am struggling to seamlessly integrate, import, or load the css framework into my project. I am unsure of whe ...

How to retrieve data from a form object sent via cloud function using App Script

Currently, I am in the process of developing a web application that can extract files from a web form and store them in a designated Google Drive folder. After the user submits the form, my goal is to trigger a cloud function using google.script.run while ...

Exploring Nested Routes and Queries in Vue JS

As a beginner in Vue, I have been exploring a demo project and struggling with understanding how routes with query parameters function. The documentation suggests using router.push({ path: 'register', query: { plan: 'private' }}) to gen ...

Encountered an error with Winston and Elasticsearch integration: "TypeError: Elasticsearch is not a constructor

I recently implemented winston-elasticsearch on my express server by following the code provided in the documentation var winston = require('winston'); var Elasticsearch = require('winston-elasticsearch'); var esTransportOpts = { le ...

Adjust the button's width as the text changes to create a dynamic animation

I'm trying to create an animation effect where the width of a button changes whenever the text inside it is updated. I've attempted using useRef on the button itself to grab its clientWidth and then applying that value to a CSS variable in order ...

How to use CSS to dynamically adjust the maximum width of an overflow container based on its children's content

I have a container with an overflowing <div> that displays multiple <ul> <li> lists. Each list always contains the same number of bordered <li> items, resembling a table. However, there may be instances where a <ul> has only ...

How can we validate the radio buttons to show a value even if none of the buttons are checked?

In my registration form, I have a gender radio option with "male" or "female" choices. Both options are unchecked initially so the user must select one. Here is the HTML code: <label class="radio"> <input type="radio" name="gender" id="option ...

Learning how to replace the alert function with Bootbox

I am currently working on a form that posts to a MySQL database. I want to replace the alert function triggered by the Malsup jQuery Form Plugin with the one created by the Bootbox plugin. Even though both plugins are functional, I struggle to integrate th ...

Displaying 'Undefined' instead of 'Cleared messages count' in the Clear Command

My goal is to display the number of deleted messages on an embed, but when the embed is sent, it shows bot deleted undefined messages. Here's a screenshot: I want it to show bot deleted ex: 15 messages. It works fine as a regular message but not on a ...

Tips for enhancing contrast in MUI dark theme modals

Currently, I am implementing MUI dark mode for my Next.js application. While the MUI modal functions perfectly in light mode, I am struggling with visibility issues when using it in dark mode. The contrast is not strong enough, making it difficult to disti ...

Is pl/pgsql block code supported by postgres-nodejs?

I am attempting to define a custom UUID variable that can be utilized across multiple queries within a transaction. Initially, I attempted using a JavaScript variable which ultimately defeated the purpose of declaring the variable on the server side. The ...

What could be the reason for NPM failing to work following an update?

Just two days ago, I updated NPM and now it's suddenly not working on my Windows 10 20H2 platform. Every action I take results in the same error message: C:\Users\ethan>npm internal/modules/cjs/loader.js:883 throw err; ^ Error: Canno ...

Theme.breakpoints.down not being acknowledged by MUI breakpoints

The Challenge: Implement a hamburger menu to replace the navMenu on tablet and smaller screens After successfully compiling in VS code terminal, encountering an error in the browser: Error Message: TypeError: Cannot read properties of undefined (reading ...

How come I am unable to pass JavaScript values to my PHP5 code?

I'm struggling with this code snippet: <?php $html=file_get_contents('testmaker_html.html'); echo $html; ?> <script type="text/javascript"> document.getElementById('save_finaly_TEST').addEventLis ...