DEV Community

Cover image for Beautiful Masonry Gallery with Bootstrap and Unsplash Random Photos
Simon Köhler
Simon Köhler

Posted on • Edited on

6 1

Beautiful Masonry Gallery with Bootstrap and Unsplash Random Photos

This beautiful gallery combines the Bootstrap framework with Masonry, Animate.css and random photos from Unsplash.

I needed an example for a client, where after each call to the gallery, a certain number of random images are loaded, and also the image sizes are determined randomly.

What could be more obvious than tapping into an image database, I thought. While researching, I came across picsum.photos and their API.

But first, here's the working example:

VIEW PEN IN FULLSCREEN MODE

What happens under the hood?

  1. Load list with images in JSON format
  2. Preload images with ImagesLoaded, then hide preloader
  3. Dynamically generate Bootstrap HTML with JavaScript
  4. Set CSS classes for Animate.css with delay on each image
  5. Put everything in a cool shape with Masonry

Pure Vanilla

No JavaScript library is used for the gallery. Everything is 100% JavaScript. For me personally, jQuery has had its day anyway.

No additional CSS so far...

So far, no additional CSS has been used, except for a few small inline styles to control the animations. Imagine what you can do with this gallery and some extra CSS! You could make it look really cool, and add a lightbox if you want.


Libraries I have used, with great thanks to the respective developers

Bootstrap 5 Framework

https://getbootstrap.com/

ImagesLoaded

https://github.com/desandro/imagesloaded

Masonry

https://masonry.desandro.com/

Animate.css

https://animate.style/

Picsum Photos

https://picsum.photos/


Your feedback is appreciated

If you like this Bootstrap Masonry Gallery PEN, feel free to leave your feedback. Also, I'm always very happy when others can use my work as the basis for great projects.

What would you improve, add, or do differently?


More Stuff

Sign up for my Newsletter!

https://simonkoehler.com/newsletter

PHP Developer

https://simonkoehler.com/php-developer

TYPO3 Freelancer

https://simonkoehler.com/typo3-freelancer

Sentry blog image

How I fixed 20 seconds of lag for every user in just 20 minutes.

Our AI agent was running 10-20 seconds slower than it should, impacting both our own developers and our early adopters. See how I used Sentry Profiling to fix it in record time.

Read more

Top comments (0)

Billboard image

The Next Generation Developer Platform

Coherence is the first Platform-as-a-Service you can control. Unlike "black-box" platforms that are opinionated about the infra you can deploy, Coherence is powered by CNC, the open-source IaC framework, which offers limitless customization.

Learn more

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay